Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用指令时,AngularJS viewContentLoaded在页面刷新和初始加载时未执行_Angularjs_Angularjs Directive_Angularjs Scope_Angularjs Routing - Fatal编程技术网

使用指令时,AngularJS 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.

当使用自定义指令并依赖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>


你知道为什么会出现这种不一致的行为吗?

我认为这个问题与一个开放的bug有关:

这真的没有办法

拟议的解决办法:

myApp.run(['$route', angular.noop]); 

对于我来说,最新的AngularJs(1.2.10)失败,出现某种“注入器错误”。

您是否将此指令应用于ngView加载的模板?