![](/img/trans.png)
[英]Display a form with multiple ng-repeat after all content has been loaded
[英]How to catch an event after all content is loaded when all controllers are initialized inside an ng-repeat in Angularjs?
<!-- Begin page content part of a pageCtrl -->
<div class="container" ng-init="pageInit();">
<div class="template {{block.type}}" ng-repeat="block in pageBlocks" my-repeat-directive>
<div ng-controller="templateCtrl" ng-include src="'partials/components/' + block.type + '.html'" ng-init="initTemplate(block);"></div>
</div>
</div>
在我的NG-重復我動態初始化一些小模板我templateCtrl從我的消息頁控件范圍傳遞的一些數據。 我的目標是在Angularjs加載和編譯我的模板的所有內容后能夠執行一些javascript。
但目前我找不到“畢竟被編譯”事件來管理一些簡單的回調操作。
我在ng-repeat上嘗試了指令和on-last-repeat操作,我嘗試了范圍。$ watch,$ timeout,$ scope。$ on('$ viewContentLoaded')...但是任何工作行為。
任何想法,建議? 提前致謝
經過一些其他的吸引力,我最終在這個解決方案,這似乎工作得很好。
這在html中
<div ng-controller="templateCtrl" ng-include src="'partials/components/' + block.type + '.html'" ng-init="initTemplate(block);" template-directive></div>
這在javascript中
app.directive('templateDirective', function($timeout){
return {
restrict: "EA",
compile: function(element, attributes){
return {
post: function(scope, element, attributes, controller, transcludeFn){
if(scope.$last){
$timeout(function(){
//operations in the callback
}, 250);
}
}
};
}
};
});
專家們同意嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.