angularjs - angular UI router | $stateParams not working -


seems $stateparams not working. passing date this:

$state.go('state2', { someparam : 'broken magic' }); 

params being ignored on target state

console.log('state2 params:', $stateparams); // return empty object {} 

code:

    var app = angular.module('app', [      'ui.router'     ]);      app.config(function($stateprovider) {       $stateprovider             .state('state1', {                 url: '',                 templateurl: 'state-1.html',                 controller : function ($scope, $state, $stateparams) {                   $scope.go = function () {                     $state.go('state2', { someparam : 'broken magic' });                   };                    console.log('state1 params:', $stateparams);                 }             })             .state('state2', {                 url: 'state2',                 templateurl: 'state-2.html',                 controller : function ($scope, $state, $stateparams) {                   $scope.go = function () {                     $state.go('state1', { someotherparam : 'lazy lizard' });                   };                    console.log('state2 params:', $stateparams);                 }             });     }); 

live example can found here

thank you.

you can't pass arbitrary parameters between states, need have them defined part of $stateprovider definition. e.g.

$stateprovider     .state('contacts.detail', {         url: "/contacts/:contactid",         templateurl: 'contacts.detail.html',         controller: function ($stateparams) {             console.log($stateparams);         }     }) ... 

the above output object contactid property defined. if go /contacts/42, $stateparams {contactid: 42}.

see documentation ui-router url routing more information.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -