Reputation: 2039
Suppose there are two run function in app:
angular.module('exmple',[])
.run(function(){
console.log('second');
})
.run(function(){
console.log('first');
});
Is there any way to execute runs based on priority?
Upvotes: 1
Views: 241
Reputation: 48968
If code is in a service, it will run in order of dependency:
angular.module('exmple',[])
.run(function(firstService){
console.log('second');
})
.service("firstService", function(){
console.log('first');
});
By having the run block define firstService
as a dependency, the dependency injector will initialize that service before running the code of the run block.
angular.module('app',[])
.run(function(firstService){
console.log('second');
})
.service("firstService", function(){
console.log('first');
});
<script src="//unpkg.com/angular/angular.js"></script>
<div ng-app="app">
</div>
Upvotes: 1