Calling order of angularjs function(config,run,directive,..)

Calling order of angularjs function(config,run,directive,..)

In Angularjs running the below sequence

  • app config
  • app run
  • directive setup
  • directive compile
  • (app controller dependencies)
  • service
  • factory
  • inner factory
  • inner service
  • app controller
  • filter
  • directive linking
  • filter render

Example 


<!DOCTYPE html>

<html >

<head>

<title>Angular Working Priority</title>

</head>

<body>

<div ng-app="myApp" ng-controller="myCtrl">

<div directive1 directive2> </div>

</div>

 

<script type="text/javascript" src= "http://ajax.googleapis.com/ajax/libs/angularjs/1.4.0/angular.js"></script>

<script>

var myApp = angular.module('myApp', []);

myApp.factory('fProvider', function() {

console.log("factory");

return function(){return "inner serv";}

});

myApp.service('sProvider', function() {

this.consoleIt = function(){return "inner fact";}

   console.log("serv");

});

myApp.directive("directive1", function() {

console.log("directive setup");

return {

compile: function() {console.log("directive compile");}

}

});

 

myApp.directive("directive2", function() {

console.log("directive setup2");

return {

link: function() {console.log("directive link");}

}

});

 

myApp.run(function() {

console.log("app run");

});

 

myApp.config( function() {

console.log("app config");

});

 

myApp.controller('myCtrl', function($scope, sProvider, fProvider) {

console.log(sProvider.consoleIt());

console.log(fProvider());

console.log("app controller");

});

 

</script>

</body>

</html>

0 Comments

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed

>