為了瞭解 app.run的用法,有找到一個範例程式(http://jsfiddle.net/ysq3m/),透過log顯示載入的流程.
顯示出的順序,依順如下:
app config
app run
directive setup
directive compile
app controller
directive link
run是在config後才會執行.
===========
範例程式html
<div ng-app="myApp" ng-controller="myCtrl">
<div test1 test2> </div>
</div>
範例程式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");
});
沒有留言:
張貼留言