2

I've set up my route using angular UI-Router like this:

routes.$inject = ['$stateProvider'];

export default function routes($stateProvider) {
    $stateProvider
    .state('the/route', {
        url: '/the/route',
        params: {
            'permissions': 'TESTPERMISSION'
        },
        views: {
            ...
        }
    })
}

and I want to access the permissions element in params in an interceptor that looks like this:

export default function locationChangeAuthInterceptor($rootScope, $state, $stateParams) {
    $rootScope.$on('$locationChangeSuccess', (evt) => {

        ...

    })
}

As you can see in the images below the logical methods of accessing the parameters doesn't work.

If I console $state.params or $stateParams I get this

Several other console.logs

Results of my attempts:

(1) $state StateService {router: UIRouter, invalidCallbacks: Array[0]}
(2) $state.params StateParams {}
    #: null
    permissions: "TESTPERMISSION"__proto__: Object
(3) $stateParams StateParams {}
    #: null
    permissions: "TESTPERMISSION"
    __proto__: Object
(4) $state.params.permissions =>  undefined
(5) $stateParams.permissions =>  undefined
(6) $state.params["permissions"] =>  undefined
(7) $stateParams["permissions"] =>  undefined
(8) angular.isObject($state.params) =>  true
(9) angular.isObject($stateParams) =>  true
(10) $state.params.stateParams =>  undefined
(11) $stateParams.stateParams =>  undefined
(12) $stateParams.permissions =>  undefined
(13) $stateParams[0] =>  undefined
(14) $stateParams[1] =>  undefined
(15) $state.params[0] =>  undefined
(16) $state.params[1] =>  undefined
(17) […$stateParams] => []length: 0__proto__: Array[0]
(18) […$stateParams] => []length: 0__proto__: Array[0]
(19) Object.keys($stateParams) => []
(20) Object.keys($state.params) => []length: 0__proto__: Array[0]
(21) $stateParams.StateService => undefined
(22) $state.params.StateService => undefined
(23) $stateParams["StateService"] => undefined
(24) $state.get("permissions") => null
2
  • Hi Eric, could you include relevant error messages as plain text? Please Commented Oct 5, 2016 at 12:15
  • 1
    Hi! Yes I've added 'Results of my attempts'. Commented Oct 5, 2016 at 12:23

1 Answer 1

0

Got a similar problem.

My guess is that the $locationChangeSuccess event should be avoided in this scenario (based on Difference between $locationChangeStart, $routeChangeStart, and $stateChangeStart) and $stateChangeSuccess should be used instead.

    $rootScope.$on('$stateChangeSuccess', function() {
        if ($state.$current.self.scroll == 'bottom')
            ;
        else                    
            $anchorScroll();
    });
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.