【发布时间】:2014-03-03 22:02:32
【问题描述】:
我在使用自定义指令并依赖 viewContentLoaded 事件运行时遇到一些不一致...
以下是问题的“基本”版本:
var myApp = angular.module('myApp',[]);
myApp.directive('someDirective', function() {
return {
restrict: 'E',
scope: {},
controller: 'MyCtrl',
templateUrl: 'my-template.html'
});
myApp.controller('MyCtrl', ['$scope', function($scope) {
$scope.$on('$viewContentLoaded', function() {
alert('Consumed viewContentLoaded...');
}
}]);
在页面刷新和初始页面加载时触发事件 viewContentLoaded get 像这样使用:
<div ng-controller="MyCtrl" ng-include="my-template.html"></div>
但是,当用作 指令:
<some-directive></some-directive>
任何想法为什么不一致的行为?
【问题讨论】:
-
您是否将此指令应用于 ngView 加载的模板?
标签: angularjs angularjs-directive angularjs-scope angularjs-routing