How to call a function after AngularJS displays all views

How to call a simple function, because AngularJS declarations 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>
+4
source share
3 answers

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

$timeout(function(){...}, 0);
+3
source

Task w. what you are trying to solve is that if you use something like ng-includeor ui-router , then you won’t know when they will complete the download until they are requested and loaded. This is a script on demand.

- angular? , - / angular:

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
})

- angular

+1

You can use the 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",
        }
0
source

Source: https://habr.com/ru/post/1584952/


All Articles