Here's the calling order:
app.config()
app.run()
- directive's compile functions (if they are found in the dom)
app.controller()
- directive's link functions (again, if found)
Here's a simple demo where you can watch each one executing (and experiment if you'd like).
Example:
index.html
<div ng-app="myApp" ng-controller="myCtrl">
<div test1 test2> </div>
</div>
index.js
var myApp = angular.module('myApp', []);
myApp.factory('aProvider', function() {
console.log("factory");
});
myApp.directive("test1", function() {
console.log("directive setup");
return {
compile: function() {console.log("directive compile");}
}
});
myApp.directive("test2", function() {
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) {
console.log("app controller");
});
Order Of execution:
app config
VM61:64 app run
VM61:51 directive setup
VM61:53 directive compile
VM61:72 app controller
VM61:59 directive link