I've tested and found that $state.transitionTo() does not use the current $stateParams (or $state.params) to populate the target params if they're not included in the second parameter.
For example, if the user is on the url /contacts/Alice
and $stateParams = {"user" : "Alice"}
and clicks on a link with with ng-click="$state.transitionTo('user.roles')"
given state definition .state('user.roles', { url: '/contacts/{user}/roles' }
an error is thrown.
If the ng-click is changed to ng-click="$state.transitionTo('user.roles', {})"
then the new url is /contacts//roles.
I checked the source code and I don't see a way to use existing $stateParams by default in the destination route.
I got around it by using ng-click="$state.transitionTo('user.roles', $stateParams)"
but I would also like the ability to override the existing $stateParams if needed.
Is this something that will be implemented in the future? For now I can use the mentioned workaround or even use a wrapper function that combines the current $stateParams with new params using jQuery.extend({}, $stateParams, {newParam1: newParam1Value}).
The goal would be to save time from writing this: ng-click="$state.transitionTo('user.roles', {user: $stateParams.user})" because I have many routes with several params.
Thanks, and thanks for creating this useful module!
I've tested and found that
$state.transitionTo()does not use the current$stateParams(or$state.params) to populate the target params if they're not included in the second parameter.For example, if the user is on the url
/contacts/Aliceand
$stateParams = {"user" : "Alice"}and clicks on a link with with
ng-click="$state.transitionTo('user.roles')"given state definition
.state('user.roles', { url: '/contacts/{user}/roles' }an error is thrown.
If the
ng-clickis changed tong-click="$state.transitionTo('user.roles', {})"then the new url is
/contacts//roles.I checked the source code and I don't see a way to use existing $stateParams by default in the destination route.
I got around it by using
ng-click="$state.transitionTo('user.roles', $stateParams)"but I would also like the ability to override the existing $stateParams if needed.
Is this something that will be implemented in the future? For now I can use the mentioned workaround or even use a wrapper function that combines the current
$stateParamswith new params usingjQuery.extend({}, $stateParams, {newParam1: newParam1Value}).The goal would be to save time from writing this:
ng-click="$state.transitionTo('user.roles', {user: $stateParams.user})"because I have many routes with several params.Thanks, and thanks for creating this useful module!