简体   繁体   中英

Checking all elements are finished loading

We have a website built using AngularJS and some components take awhile to load. What I would to do is create an event that would be triggered when all components are loaded. I could use tag selector with load event. However, the custom tag for for the components may change down the road and I prefer not to rely on that. So the question is...is there a way to create an event handler that doesn't rely on tag name but will be triggered when all loadings on the page is done.

I think this might useful to you if you use angular UI route.

$viewContentLoading - fired once the view begins loading, before the DOM is rendered. The '$rootScope' broadcasts the event.

$rootScope.$on('$viewContentLoading', 
function(event, viewConfig){ 
   //Do something
});

$viewContentLoaded - fired once the view is loaded, after the DOM is rendered. The '$scope' of the view emits the event.

$scope.$on('$viewContentLoaded', 
function(event){ 

//Do something
});

OR you can try angular $window object.

$window.onload = function(e) {
  //do something
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM