Reputation: 1921
I am using angular-permission and try to redirect users according to their roles.
I am trying to make something like this, but am not able to inject rootScope inside app.config to get the user:
redirectTo: function(){
if($rootScope.isAdmin){
}
else{
}
return 'login';
}
and here's the config section inside my app.js file
.config(['$stateProvider', '$locationProvider', '$datepickerProvider', '$timepickerProvider', 'RestangularProvider', '$httpProvider', '$scrollspyProvider', function ($stateProvider, $locationProvider, $datepickerProvider, $timepickerProvider, Restangular, $httpProvider, $scrollspyProvider) {
$stateProvider
.state('test', {
url: '/test',
templateUrl: "/test.html",
data: {
title: 'test',
pageTitle: 'test',
access: 'authenticated',
permissions: {
only: ['admin'],
redirectTo: function(){
//////////////////////////////////
}
}
}
})
}])
Is there a different way to do this ?
Upvotes: 0
Views: 540
Reputation: 3967
Without seeing your app.config - I can tell you that the best place to do this is probably in app.run
instead of app.config
.
app.run(['$rootScope', function($rootScope){
// stuff
}]);
Here is the source confirming that you can't use $rootScope in .config. Only in .run. https://stackoverflow.com/a/10489658/1543447
Upvotes: 2