Skip to content

It would be nice to use transitionTo to define parameters that aren't necessarily in the url. #426

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

Closed
Bretto opened this issue Sep 16, 2013 · 13 comments

Comments

@Bretto
Copy link

Bretto commented Sep 16, 2013

In the context of a mobile application the transtionTo method IMO feels like it's missing the ability to pass data from state to state. I understand that the concern for this missing feature is that the view would be loosing it's data on a reload of the url. As this concern is not necessarily applicable to all contexts, could we be provided with a way to communicate data from view to view via the ui-router without it being part of the url ?

@laurelnaiad
Copy link

Don't know if that's particular to mobile but services are one generally accepted way to share lomger lasting data.

@Bretto
Copy link
Author

Bretto commented Sep 16, 2013

Yes indeed, the thing is (I feel...) it's introducing "global longer lasting data" when what is needed is a "contextual short lasting data transit" between specific views. Is there anyway to make this work ?

@laurelnaiad
Copy link

I believe that if you define your state as having a params property instead of a url you can do that.

@Bretto
Copy link
Author

Bretto commented Sep 16, 2013

I will have to investigate this... I currently don't understand how I can substitute one for the other... Is there any example of this ? is this substitution technic the equivalent in it's features ?

@laurelnaiad
Copy link

I think you can sort of see it here https://github.com/angular-ui/ui-router/blob/master/sample/states.js#L229. I'm on my tablet and can't type much.

@Bretto
Copy link
Author

Bretto commented Sep 16, 2013

OK after investigation in the params option I sorry to inform you that i could not make it work...

.state('app.bordereau', {
            url: '/bordereau',
            views: {
                'page@app': {
                    controller: function($stateParams, $state){
                        $state.transitionTo('app.etablissement', { bordereau: 'bordereau' });
                    },
                    templateUrl: 'partials/bordereau.html'
                }
            }
        })

.state('app.etablissement', {
            views: {
                params: ['bordereau'],
                'page@app': {
                    controller: function($stateParams, $state){
                        console.log('$state.params:', $state.params.brodereau);
                        console.log('$stateParams:', $stateParams.brodereau);
                    },
                    templateUrl: 'partials/etablissement.html'
                }
            }
        })

$state.params and $stateParams are always empty objects. I read that there were some issue with it ( the object was converted to a string etc.. ) can someone give a status on this issue ? or create a jsfidle with a transitionTo passing a complex object to a state without url ? this is the version I am using @Version v0.0.2-dev-2013-08-19
Thank you for your feed back @stu-salsbury have a nice day or a good sleep... ;)

@laurelnaiad
Copy link

Try putting params on the state not views.

@Bretto
Copy link
Author

Bretto commented Sep 17, 2013

Ok this works thanks for the tip. The problem remains though, as the complex object is being converted to a string...
The PARAMS method seems perfect for sharing data from view to view in the mobile app context but the fact that it's being converted to a string is really problematic... could someone explain the reason behind this ?

@laurelnaiad
Copy link

I think you're throwing a lob?

$state.transitionTo('app.etablissement', { bordereau: 'bordereau' });

You're passing a string... still not clear to me what this has to do with mobile, but I'll take your word for it :)

@Bretto
Copy link
Author

Bretto commented Sep 17, 2013

I know this was a test, i then removed the single quotes, and bordereau becomes a reference to an entity object spawned by JayData... I am currently persisting states between views via service... as the values set in this service is long lasting you need to never forget to remove it once you are done with it. The thing is if it was attach to the stateParams you would not need to remove it as it's been destroy and garbage collected after use, plus the mechanism of transitionTo seems the right candidate to transit with additional data. So the issue of the conversion to a string of my entityObject remains... what is the rational for it ?

@laurelnaiad
Copy link

I'm surprised. I thought the object was be preserved.

@nateabele
Copy link
Contributor

Right now parameters are string-only. This will be fixed with the implementation of #454. Keep an eye out there.

@Bretto
Copy link
Author

Bretto commented Mar 27, 2014

can we pass objects these days with transitionTo ?

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