angularjs - $stateParams returning undefined -
i have these routes defined:
.state('sport', url: '/sport' templateurl: '/templates/sport' controller: 'sportctrl' ) .state('sport.selected' url: '/:sport' templateurl: '/templates/sport' controller: 'sportctrl' )
and have controller trying use :sport param given sport.selected state.
angular.module('myapp') .controller('sportctrl', ['$scope', 'parseservice', '$stateparams', function ($scope, parseservice, $stateparams) { var sporturl = $stateparams.sport; ... });
for reason, returns undefined when call $stateparams.sport in controller, though think defined in routes. why case?
thanks help!
when access url /sport/12
, sportctrl
instantiated twice: once state sport
, , once state sport.selected
. , first state, there no parameter associated state, $stateparams.sport
undefined.
note it's quite strange use same template state , sub-state. you'll have template embedded inside ui-view div of same template.
Comments
Post a Comment