javascript - Get params from URL using $stateParams, UI-router. Undefined Value -


i passing value 1 state using ui-router. in controller when url updated trying access second parameter of url using $stateparams, reason can access first parameter second 1 undefined. code:

state 1, url:

 http://localhost:16009/#/5nqeapqlv21/ 

state 2, url:

 http://localhost:16009/#/5nqeapqlv21/details/pp163ku3dor 

candidatecontoller.js:

//go state 2 (same controller parent , child views) $state.go('index.details', { "submissionidd": publicsubmissionid });  //when located in new state , new url: console.log($stateparams.submissionidd); //shows undefined  console.log($stateparams.token);  //shows 5nqeapqlv21 

app.js:

$stateprovider            .state('index',         {             url: '/:token/',             views: {                 '': {                     templateurl: 'angularjs/templates/indexview.html',                     controller: 'candidatecontroller candctrl'                 },                 'sectioncandidate@index': {                     templateurl: (_isnotmobile)                        ? 'angularjs/templates/candidatesview.html'                        : 'angularjs/templates/candidatesmobileview.html'                 }             }          })                 .state('index.details', {          url: 'details/{submissionidd}',          views: {              'sectioncandidate@index': {                  templateurl: (_isnotmobile)                     ? 'angularjs/templates/candidateview.html'                     : 'angularjs/templates/candidatemobileview.html'              }          }      }) 

you experience standard behavior of ui-router , parent/child state defintion:

  • parent state declares $stateparams (as url: '/:token/') - there 1 declared - token
  • child state gets parent(s), plus declares new parameter (as url: 'details/{submissionidd}') - has both defined - token , submissionidd,

so, while child has access both params, parent state has token parameter

state 1 === parent, url:

http://localhost:16009/#/5nqeapqlv21/ 

here have submissionidd undefined

state 2 === child, url:

http://localhost:16009/#/5nqeapqlv21/details/pp163ku3dor 

both there submissionidd=pp163ku3dor , token=5nqeapqlv21

extend - there working plunker

this states definition (in plunker bit adjusted)

.state('index',     {         url: '/:token/',         views: {             '': {                 templateurl: 'indexview.html',                 controller: 'candidatecontroller candctrl'             },             'sectioncandidate@index': {                 templateurl: 'parent.html'             }         }      })             .state('index.details', {      url: 'details/{submissionidd}',      views: {          'sectioncandidate@index': {              templateurl:'child.html',          }     }) 

will show state params these links

href <a href="#/5nqeapqlv21/"> <a href="#/5nqeapqlv21/details/pp163ku3dor"> <a href="#/5nqeapqlv21/details/other"> ui-sref <a ui-sref="index({token: '5nqeapqlv21'})"> <a ui-sref="index.details({token: '5nqeapqlv21', submissionidd: 'another'})"> 

check here


Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -