Angular Check Authenticate User, Before The Template Is Served
When the route change, I try to access to /settings .when('/settings', { templateUrl: 'partials/settings', controller: 'SettingsCtrl', authenticate: true }) .run(fu
Solution 1:
You should use the resolve
mechanism of angularjs controllers. This way you can define any pre-requisite (service injection, waiting promises, etc) of your controller before render it.
- See angular doc : https://docs.angularjs.org/api/ngRoute/provider/$routeProvider
- See a working example on angular-app project : https://github.com/angular-app/angular-app/tree/master/client/src/common/security
Example :
.when('/settings', {
templateUrl: 'partials/settings',
controller: 'SettingsCtrl',
authenticate: true,
resolve: {
isUserLogged: ['yourservice' , function(yourservice) {
return yourservice.isUserLoggedPromise();
}]
}
})
Your screen will be rendered only after (and if) isUserLoggedPromise
is resolved
Post a Comment for "Angular Check Authenticate User, Before The Template Is Served"