Skip to content Skip to sidebar Skip to footer

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.

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"