admin管理员组

文章数量:1312677

How to call a simple function, after all AngularJS views loaded successfully.

function hello() {
  alert('All AngularJS works are done');
}

<!-- Below code is example about how I need a function for AngularJS loaded event -->
app.onAngularLoaded(function () { hello(); });
</script>

How to call a simple function, after all AngularJS views loaded successfully.

function hello() {
  alert('All AngularJS works are done');
}

<!-- Below code is example about how I need a function for AngularJS loaded event -->
app.onAngularLoaded(function () { hello(); });
</script>
Share Improve this question edited Apr 27, 2015 at 17:06 αƞjiβ 3,25615 gold badges63 silver badges104 bronze badges asked Apr 27, 2015 at 16:58 Vinoth KannanVinoth Kannan 2425 silver badges16 bronze badges 1
  • Maybe it help: stackoverflow./questions/14968690/… – Wédney Yuri Commented Apr 27, 2015 at 17:13
Add a ment  | 

3 Answers 3

Reset to default 4

Try setting a timeout with a value of 0. That will happen after the current set of digest cycles.

$timeout(function(){...}, 0);

The problem w. what you are trying to tackle is that if you are using something like ng-include or ui-router then you won't know when those are finished loading until they are requested and loaded. It's an on-demand scenario.

You may however be looking to do something post-bootstrapping of the angular process? If that is the case you need to do something like this on you main/root angular module:

angular.module('app', [ ... any ng-dependencies here ...])
.controller(...)
.controller(...)
.directive(...)
.service(...)

//then here is where you do your post-bootstrapping logic
.run( function(){
   //code here
})

more info here - angular module docs

You can use directive to get it.

var homeApp = angular.module('home', ['ui.bootstrap', 'ngAnimate']);
homeApp
    .directive("pagecontent",
    function() {
        return {
            restrict: "E",
            link: function() {
                alert('All AngularJS works are done');
            },

            templateUrl: "template path",
        }

本文标签: javascriptHow to call a function after AngularJS render all viewsStack Overflow