Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$state.transitionTo(): Use the current $stateParams by default #167

Closed
pholly opened this issue Jun 6, 2013 · 4 comments
Closed

$state.transitionTo(): Use the current $stateParams by default #167

pholly opened this issue Jun 6, 2013 · 4 comments

Comments

@pholly
Copy link

pholly commented Jun 6, 2013

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!

@ksperling
Copy link
Contributor

That's correct, this is not currently implemented.

The plan is to augment the current behaviour so that any parameters that are shared between the two states will be defaulted from the current $stateParams (however this won't apply to parameters that are named the same "by coincidence" to avoid unintended behaviours).

@pholly
Copy link
Author

pholly commented Jun 7, 2013

Great. Is there a ui-router roadmap by any chance?

@timkindberg
Copy link
Contributor

@pholly
Copy link
Author

pholly commented Jun 7, 2013

Awesome! Would be great if ui-router gets assimilated into angular base. If not, as long as it's the defacto standard for routing/state management that would be fine too.

@pholly pholly closed this as completed Jun 7, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants