state.$$permissionState is not a function
Closed this issue · 5 comments
I get this error using the unminified version of angular-permission
but only in one particular state in my app. It appears to me that for some reason angular-permission
does not decorate it with this $$permissionState
property as it does on the other states.
Here is a sample of it's state definition:
$stateProvider.state('activation', {
url: '/activate',
templateUrl: 'activation.html',
controller: 'LicenseCtrl as vm',
data: {
permissions: {
only: 'canActivate',
redirectTo: 'root.home'
}
}
});
The canActivate
permission is always returning true
so that we can always access this state. The other states I am redirecting to activation have following definition:
.state('root.home.settings.offices', {
url: '/offices',
controller: 'OfficeBrowserCtrl as vm',
templateUrl: 'offices.html',
data: {
permissions: {
only: 'isActivated',
redirectTo: 'activation'
}
}
});
Here is the isActivated
permission:
PermPermissionStore
.definePermission('isActivated', function() {
return License.isActivated().then(function(isActivated) {
return !!isActivated;
});
});
In the case that the isActivated
permission is rejected I receive an error code from server that is intercepted and invalidates the License service. When first received the error code is caught by the interceptor that emits a signal. In the run
method of the module is the handling:
.run(function(License, $rootScope, $state) {
$rootScope.$on('not_activated', function(event) {
License.invalidate();
$state.go('activation');
});
})
The $state.go
statement is causing the error. Any clues why is it happening? The redirect is happening on the second attempt to access the offices
state for example. I tried also to inherit a base abstract state and then use activation
but no luck again..
As I see activation
state is not inheriting from your root state, so it may not have DI module dependency to angular-permissions when loaded. So of solutions will be changing your state to root.activation
(if that won't mess with your views) to properly handle module dependencies.
My root
state has already the isActivated
permission. So if I make activation
to inherit it I should add except
permisssion for it and it didn't look very logic to me so I left it separate. Can't I just declare in the license/activation module(because it's another module) too that it depends on angular-permission
?
Yes you can of course :)
@masterspambot I just tried and adding angular-permission
to the DI of the module stopped the error from happening. But does that mean I should add it to all my submodules just to be sure that it's decorating all substates?
No you don't need to. The case is that activation
is ui-router's root state the same way your root
state is. All deps are inherited down from from the root itself. You just need assure you have properly set deps only for those.