2

On a specific state user is clicking link to other state in which there is a resolve condition that checks if user has permission. How to stop changing state to new one if user hasn't permission?

Lajos Veres
  • 13,595
  • 7
  • 43
  • 56
piernik
  • 3,507
  • 3
  • 42
  • 84

1 Answers1

1
var routesThatRequireAuth = ['/user', '/account', '/messages']; 
var hasPermisions = false;

$rootScope.$on('$stateChangeStart', function(event, toState, toParams, fromState, fromParams) {
  if($.inArray(toState.url,routesThatRequireAuth)>-1 && !hasPermisions) {

    event.preventDefault();
    // ...
    // alert message
  }
}); 
Maciej Osytek
  • 36
  • 1
  • 4
  • Welcome to stackoverflow, @Maciej. Thank you for taking the time to answer. In the future, i would recommend adding an explanation of how this answers the OP's (original poster) answer. – Olivier De Meulder Sep 25 '15 at 20:37