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 需要注入