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

Passing objects as params between states on transition #400

Closed
santyclaz opened this issue Sep 10, 2013 · 5 comments
Closed

Passing objects as params between states on transition #400

santyclaz opened this issue Sep 10, 2013 · 5 comments

Comments

@santyclaz
Copy link

Currently you can't pass objects as params when you transition between states. I am curious about the reasons that led to this design decision, and perhaps clean alternatives to what I am trying to do.

Some code snippets to just make clear what I am talking about:

...
$stateProvder.state('add-order', {
    templateUrl: 'order/add.html',
    controller: 'addOrderController',
    params: ['advertiser']
});
...
...
// $scope.selectedAdvertiser is an Advertiser object
$state.transitionTo('add-order', {advertiser: $scope.selectedAdvertiser});
...
...
controller('addOrderController', [..., '$stateParams', function(..., $stateParams) {
    console.log($stateParams); // output: Object {advertiser: "[object Object]"}
    ...
}]);
@nateabele
Copy link
Contributor

Currently all values are normalized to strings, because parameters are handled the same for both URL and non-URL states. This will go away when #125 is implemented, so you can keep an eye out there.

If you're okay with a hacky solution in the meantime, you should be able to modify the normalize() function, and change:

normalized[name] = (value != null) ? String(value) : null;

to:

normalized[name] = (value != null) ? value : null;

I'm not sure what effect that would have on states with URLs, but you could give it a try.

@santyclaz
Copy link
Author

@nateabele Thanks! I will implement the hacky solution for now and update the library when #125 gets pushed.

@pulkitsinghal
Copy link

@nateabele It seems that issue was resolved but there still isn't a way to pass objects as @santyclaz initially pointed out. Its a really long comment list over there with the most recent one only 8 days old as of my writing. So is it not working still or is it just that I don't have the latest release? What version officially did it get sorted out in?

@nateabele
Copy link
Contributor

@pulkitsinghal This is a duplicate. Please follow #125.

@pulkitsinghal
Copy link

@nateabele that was getting a bit hard to follow so I thought I'd get a clarification here but I'll post there sure.

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