执行code。在角初始化结束,ngCloak显示初始化、结束、code、ngCloak

由网友(高傲得不顧一屑)分享简介:我已经写在角与ngCloak指令的网页。它被装载在一个动态的iframe大小与 pym.js 。I have a webpage written in angular with an ngCloak directive. It is loaded in a dynamically sized iframe with...

我已经写在角与ngCloak指令的网页。它被装载在一个动态的iframe大小与 pym.js 。

I have a webpage written in angular with an ngCloak directive. It is loaded in a dynamically sized iframe with pym.js.

麻烦的是,页面不会出现,除非我调整浏览器或触发resize事件,或者在页面加载后调用pymChild.sendHeight()。

The trouble is that the page does not appear unless I resize the browser or trigger a resize event, or call pymChild.sendHeight() after the page loads.

我没有看到ngCloak虽然任何事件。是否有一个角事件呈现页面时,控制器初始化?

I don't see any events associated with ngCloak though. Is there an angular event for "page is rendered, controllers are initialized"?

推荐答案

您可以写在 postLink 函数执行的回调指令,因为postLink将被称为最后的在 $编译的生命周期。

You could write a directive that execute a callback in postLink function, since the postLink will be called last in the $compile life cycle.

.directive('onInitialized', function ($parse) {
  return {
    restrict: 'A',
    priority: 1000, // to ensure that the postLink run last.
    link: function postLink(scope, element, attrs) {
      $parse(attrs.onInitialized)(scope);
    }
  }
});

和把它放在你想知道,当它和它的所有模板就绪 decendants已经得到编制的元素,例如:

and place it at the element that you would like to know when it and all its template-ready decendants have got compiled, for example:

<body ng-controller="MainCtrl" on-initialized="hello()">

,并在 MainCtrl 控制器:

app.controller('MainCtrl', function($scope) {
  $scope.name = 'World';

  $scope.hello = function () {
    console.log('Hello ' + $scope.name);
  };
})

有关模板就绪,我的意思是所有指令除了:指令与 templateUrl 和模板还没有准备好在$ templateCache然而,因为他们将得到异步编译。

For template-ready, I mean all directives except: directives with templateUrl and the template haven't ready in the $templateCache yet, since they will get compiled asynchronously.

希望这有助于。

阅读全文

相关推荐

最新文章