http://www.panda-os.com/2015/01/angularjs-jquery-dom-ready/#.Vxueu9yUcYw
There are several solutions to this issue. I’ll list them from the best to the worst in the AngularJS best practices way:
- 1. Listen to the $viewContentLoaded broadcast event.
123
$scope.$on('$viewContentLoaded',function(event) {//Your code goes here.}); - 2. Use $timeout with zero seconds timeout so the view will be loaded, and then our code will be executed in the next digest cycle.
123
$timeout(function() {//Your code goes here.}); - 3. Use the jQuery old fashioned way. (Works in most scenarios)
123
jQuery(window).ready(function() {//Your code goes here.})
$timeout 需要注入
本文介绍了在 AngularJS 中确保 DOM 完全加载后再执行特定代码的几种方法。从最佳到次佳依次为:监听 $viewContentLoaded 事件、使用带有零秒延迟的 $timeout 以及传统的 jQuery ready 方法。
297

被折叠的 条评论
为什么被折叠?



