angular-acl icon indicating copy to clipboard operation
angular-acl copied to clipboard

Does it work with ui-router

Open amrinder23 opened this issue 9 years ago • 8 comments

Hi Mike,

Can i use it in an application using ui-router for routing.

Regards Amrinder

amrinder23 avatar Jan 28 '16 03:01 amrinder23

@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:

mikemclin avatar Jan 28 '16 11:01 mikemclin

@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');
    }
  });
}]);

yhonguevara avatar Jan 29 '16 00:01 yhonguevara

@yhon92 thanks for the comment :+1:

mikemclin avatar Jan 29 '16 15:01 mikemclin

Thanks @yhon92 .. I will try this. :+1:

amrinder23 avatar Jan 30 '16 00:01 amrinder23

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.

amrinder23 avatar Feb 02 '16 03:02 amrinder23

@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 avatar Feb 02 '16 03:02 amrinder23

@amrinder23

  1. what version you're using ui-router?

  2. 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.

yhonguevara avatar Feb 03 '16 00:02 yhonguevara

@yhon92 I am using v0.2.15 of ui-router

amrinder23 avatar Feb 03 '16 02:02 amrinder23