【问题标题】:AngularJS viewContentLoaded not executing on page refresh and initial load while using directiveAngularJS viewContentLoaded 在使用指令时未在页面刷新和初始加载时执行
【发布时间】: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


【解决方案1】:

我认为该问题与一个未解决的错误有关:

https://github.com/angular/angular.js/issues/1213

真的没有办法解决这个问题。

建议的解决方法:

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

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

【讨论】:

    猜你喜欢
    • 2016-04-03
    • 2013-06-18
    • 2018-10-28
    • 2014-08-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多