In the angular DOM to load before the specified function call

Today found in the page using the angular data binding JS rendering is executed too quickly, to the DOM are not ready, directly on the error, then check the information
first: We can use ng-init command to help us achieve

// html
<div ng-init="init()"></div>

$scope.init = function() {
    // to do 
}

The second: If the license, you can also use setTimeOut can be achieved, but this is not recommended, because the use of the time difference is not very strict

$scope.init = function() {
    // to do 
    setTimeOut(function(){
    	XXXXX;
    },1000)
}
$scope.init ();
Published 53 original articles · won praise 33 · views 110 000 +

Guess you like

Origin blog.csdn.net/weixin_42966484/article/details/90371565