Reputation: 3440
What is the best way to handle app start event ?
I want to automatic login user after app start or app refresh.
Where to put my code?
Upvotes: 2
Views: 5365
Reputation: 4671
Any code you want to run on app start (or app refresh) should go inside module.run()
. You can inject and use dependencies such as http
or other services just as you can in controllers, etc. For example:
var app = ng.module('app', [/* top-level dependencies, modules */]);
app.run(['$http', '$q', function ($http, $q) {
// any code you want to run on app start/refresh, using any dependencies you've injected
}]);
Upvotes: 10