Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does it work with ui-router #15

Open
amrinder23 opened this issue Jan 28, 2016 · 8 comments
Open

Does it work with ui-router #15

amrinder23 opened this issue Jan 28, 2016 · 8 comments

Comments

@amrinder23
Copy link

Hi Mike,

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

Regards
Amrinder

@mikemclin
Copy link
Owner

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

@yhonguevara
Copy link

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

@mikemclin
Copy link
Owner

@yhon92 thanks for the comment 👍

@amrinder23
Copy link
Author

Thanks @yhon92 .. I will try this. 👍

@amrinder23
Copy link
Author

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
Copy link
Author

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

@yhonguevara
Copy link

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

@amrinder23
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants