javascript - AngularJS - Access $statParams from a parent controller with UI-Router -


i have rather complicated prototype app have been asked throw together... in app have routes / states defined using ui-router, here code app.js file, can see 1 parent , child route / state:

.state('myapp.loggedinhome.contacts.default', {         url: '/:profileid', // myurl.com/home/contacts/31333194         template: '<ui-view/>',         publicaccess: false     }) // nested state contacts profile... .state('myapp.loggedinhome.contacts.default.news', {     url: '/news',  // myurl.com/home/contacts/31333194/news     templateurl: '/prototype/app/people/views/news.html',     publicaccess: false,     controller: 'visitorsnewsctrl' }) 

now in visitorsnewsctrl controller want access :profileid defined in parent root... when try access using $stateparams service undefined! doing wrong in controller?

.controller('visitorsctrl', ['$scope', '$stateparams',      function ($scope, $stateparams) {        console.log($stateparams.profileid); // undefined                                             // $stateparams empty object 

i redirecting state so...

$state.go('myapp.loggedinhome.contacts.default.news', { profileid: 123456 } );

however value profileid undefined? value appears in url!

you need add potential params url in state definition this: url: '/news/:profileid'

if use $state.go('myapp.loggedinhome.contacts.default.news', {profileid: 1234}) should able access $stateparams.profileid

example definition:

$stateprovider     .state('contacts.detail', {         url: "/contacts/:contactid",         templateurl: 'contacts.detail.html',         controller: function ($stateparams) {             // if got here url of /contacts/42             expect($stateparams).tobe({contactid: "42"});         }     }) 

Comments

Popular posts from this blog

How to show in django cms breadcrumbs full path? -

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -