http://stackoverflow.com/questions/20663076/angularjs-app-run-documentation
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).
From Angular's module docs:
============
very good example:
============
index.html:54 app config
index.html:50 app run
index.html:37 directive setup
index.html:39 directive compile
index.html:58 app controller
index.html:45 directive link
<script>
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");
});
</script>
================
沒有留言:
張貼留言