javascript - AngularJS accessing $stateParams in run function -


i able access url parameters in run function , make actions based on params. however, pretty surprised see ui.router's $stateparams object empty in run function.

angular.module('app', ['ui.router']) .run(['$rootscope', '$state', '$stateparams', '$location', function($rootscope, $state, $stateparams, $location) {     $rootscope.$state = $state;     $rootscope.location = $location;     $rootscope.$stateparams = $stateparams;     $rootscope.$on('$statechangestart', function(event, tostate) {       if (tostate.name === 'main') {       event.preventdefault();       $state.go('main.child', {          param: 1        })       }     });     console.log('$stateparams empty!');     console.log($stateparams);     console.log($rootscope.$stateparams); }]) .config(['$stateprovider', '$urlrouterprovider', '$locationprovider', function($stateprovider, $urlrouterprovider, $locationprovider) {      $stateprovider         .state('main', {              url: '',             template: '<div>hey</div><div ui-view></div>'          })         .state('main.child', {              url: '/:param',             template: 'child state template'           }); }]); 

is possible access params accessed $stateparams in run function? or available in config function? why not accessible in run function?

plnkr: http://plnkr.co/edit/1yxkrmr48lyxbgxwq66y?p=preview

thanks help.

it looks using statechangestart event , can access parameters in event:

 $rootscope.$on('$statechangestart', function (event, tostate, toparams, fromstate, fromparams) { //you code goes here console.log(toparams); } 

i using add custom logic parametrs (authentication redirects)


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -