angular-acl
angular-acl copied to clipboard
Does it work with ui-router
Hi Mike,
Can i use it in an application using ui-router for routing.
Regards Amrinder
@amrinder23 I m not as familiar with UI Router. I can figure it out and post here eventually (I'm getting ready to leave for work). In the meantime, I'd suggest searching "angular ui router protect routes" or something similar to see the mechanism for bailing out of a route based on some sort of logic. Then I'd implement this angular-acl
package into that flow.
If you find a good solution, please share :smile:
@amrinder23 If you use !, the only thing different is the statement app.run ()
app.run(['$rootScope', '$state', function ($rootScope, $state) {
// If the route change failed due to our "Unauthorized" error, redirect them
$rootScope.$on('$stateChangeError', function (event, toState, toParams, fromState, fromParams, rejection) {
if (rejection === 'Unauthorized') {
$state.go('home');
}
});
}]);
@yhon92 thanks for the comment :+1:
Thanks @yhon92 .. I will try this. :+1:
Thanks @mikemclin for an awesome service. Thanks @yhon92 it worked for me. $state didnt work in app.run method. I had to get its instance using $injector.get("$state"). Then it worked for me.
@mikemclin .. Just another question. After implementing angular-acl in my application, when i refresh the browser it considers it as $stateChangeError and it goes into that code block (rejection==='Unauthorized') and sets the current state to the one set there.
Can't we remain on the same state ?
@amrinder23
-
what version you're using ui-router?
-
I use $stateChangeStart to capture the event to load the browser, and if the key there AclService in the localStorage use the function AclService.resume(); to continue operation.
@yhon92 I am using v0.2.15 of ui-router