我有一个用角写的带有ngCloak指令的网页。它用pym.js加载在动态大小的iframe中。
问题是,除非我调整浏览器的大小或触发一个调整大小的事件,或者在页面加载后调用pymChild.sendHeight(),否则页面就不会出现。
不过,我没有看到任何与ngCloak相关的事件。是否有“页面呈现,控制器初始化”的角度事件?
发布于 2014-07-18 14:56:22
有$timeout服务:
$timeout(function() {
// this code will execute after the render phase
});
发布于 2014-07-18 16:30:56
您可以编写一个指令,在postLink
函数中执行回调,因为postLink将在$compile
生命周期中最后调用。
.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);
}
}
});
并将其放在您想知道的元素中,例如:
<body ng-controller="MainCtrl" on-initialized="hello()">
在MainCtrl
控制器中:
app.controller('MainCtrl', function($scope) {
$scope.name = 'World';
$scope.hello = function () {
console.log('Hello ' + $scope.name);
};
})
对于template-ready
,我指的是除了:带有templateUrl
的指令和模板尚未在$templateCache中准备好的所有指令,因为它们将被异步编译。
希望这能有所帮助。
https://stackoverflow.com/questions/24827873
复制相似问题