使用指令时,AngularJS viewContentLoaded在页面刷新和初始加载时未执行
当使用自定义指令并依赖viewContentLoaded事件运行时,我遇到一些不一致 以下是问题的“基本”版本:使用指令时,AngularJS viewContentLoaded在页面刷新和初始加载时未执行,angularjs,angularjs-directive,angularjs-scope,angularjs-routing,Angularjs,Angularjs Directive,Angularjs Scope,Angularjs Routing,当使用自定义指令并依赖viewContentLoaded事件运行时,我遇到一些不一致 以下是问题的“基本”版本: var myApp = angular.module('myApp',[]); myApp.directive('someDirective', function() { return { restrict: 'E', scope: {}, controller: 'MyCtrl', templateUrl: 'my-template.
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>
你知道为什么会出现这种不一致的行为吗?我认为这个问题与一个开放的bug有关: 这真的没有办法 拟议的解决办法:
myApp.run(['$route', angular.noop]);
对于我来说,最新的AngularJs(1.2.10)失败,出现某种“注入器错误”。您是否将此指令应用于ngView加载的模板?