0

What i am trying to do

As mentioned in questions title, i want to check authorization and authentication of next routes so i have made custom properties on routes and trying to access them in $locationChageStart.

Problem i am facing is

the event , next , prev/current arguments are correct but custom properties are returning undefined

My code

myModule.run(function($rootScope,authService,$state){

        $rootScope.$on("$locationChangeStart",function(e,next,prev){

            console.log(e+","+next+","+prev);  //correct
            console.log(next.reqAuthentication); // returning undefined
            console.log(prev.reqAuthentication); // returning undefined
        });
    })

and in Config routes are like

           .state('profile.company', {
            url: "/company",
            templateUrl: 'partials/companyprofile.html',
            controller: 'adminCtrl',
            reqAuthentication:true,
            authenticateRole:['a','b',"c"]

        })
        .state('profile.messages', {
            url: "/messages",
            templateUrl: 'partials/chat.html',
            controller: 'adminCtrl',
            reqAuthentication:true,
            authenticateRole:['a','b',"b"]
            })

Note: I am using ui routes so i think there is some problem i am mixing it up with ngRoute

A.B
  • 20,110
  • 3
  • 37
  • 71

1 Answers1

2

You can use this:

$rootScope.$on('$stateChangeSuccess', 
function(event, toState, toParams, fromState, fromParams){ ... })

if you want to work with states.

More details you can find https://github.com/angular-ui/ui-router/wiki

Alexey Semenyuk
  • 3,263
  • 2
  • 32
  • 36
  • thanks for the answer,i already tried it fromState.reqAuthentication and toState.reqAuthentication both are undefined – A.B Jan 04 '15 at 13:43
  • 1
    thanks, resolved can you explain whats toParams and fromParams reefer to? – A.B Jan 04 '15 at 13:48
  • Maybe I had been quick with toParams and fromParams. You are right need to write fromState.reqAuthentication and toState.reqAuthentication. Because toParams and fromParams allow going to a sibling state that shares parameters specified in a parent state: http://stackoverflow.com/questions/19516771/state-go-toparams-not-passed-to-stateparams – Alexey Semenyuk Jan 04 '15 at 16:41