【发布时间】:2016-12-23 19:39:15
【问题描述】:
当 AngularJS 完成所有路由、组件和指令的渲染后,有什么方法可以运行脚本吗?
例如,当所有带有 templateURL 的组件和指令都完成渲染时。
【问题讨论】:
标签: angularjs domready angular-component-router angular-components
当 AngularJS 完成所有路由、组件和指令的渲染后,有什么方法可以运行脚本吗?
例如,当所有带有 templateURL 的组件和指令都完成渲染时。
【问题讨论】:
标签: angularjs domready angular-component-router angular-components
$timeout 是在 DOM 完成渲染后需要执行某些操作时的最佳方式:
$timeout(function() {
});
http://lorenzmerdian.blogspot.de/2013/03/how-to-handle-dom-updates-in-angularjs.html
【讨论】:
请使用$timeout服务,延迟为0ms:
$timeout(function() {
//this code will be invoked when all directives and components will be rendered
});
【讨论】:
如果是出于显示目的,您可以使用ngCloak 指令。
根据 Angular 文档,它用于防止 Angular html 模板在您的应用程序加载时被浏览器以原始(未编译)形式短暂显示。使用该指令可以避免 html 模板显示引起的不良闪烁效果。
您也可以使用$http.pendingRequests。
【讨论】: