Skip to content

transitionTo with params doesn't work in 0.2.11 #1319

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
antmir opened this issue Aug 31, 2014 · 9 comments
Closed

transitionTo with params doesn't work in 0.2.11 #1319

antmir opened this issue Aug 31, 2014 · 9 comments

Comments

@antmir
Copy link

antmir commented Aug 31, 2014

I think something bad happened to stateParams in 0.2.11 (and I didn't find any open issue on this)

a code snippet:

Controller1:

$state.transitionTo('S.T', {'id':2, 'conversation':3});


StateProvider:

.state('S.T', {
templateUrl: 'views/something.html',
controller: 'Controller2',
params: ['id', 'conversation']
})


in Controller2 $stateParams is {0:undefined, 1: undefined}

Moving back to angular-ui-router#0.2.10 fixes this issue.

Thank you

@antmir
Copy link
Author

antmir commented Sep 1, 2014

I failed making transitionTo work in plunkr, sorry.
This is the code �http://plnkr.co/edit/ewmHII?p=preview (but transitionTo just doesn't work).
I hope it can help.
If I'm right, with 0.2.11 $stateParams for anotherCtrl will be {0:undefined, 1:undefined}, while in 0.2.10 it will be the "right" one (for this example: {'id': 'given id', 'conv': 'nice conversation'}).
Thank you.

@nateabele
Copy link
Contributor

By "doesn't work", do you mean that you can't reproduce your issue? Because I just clicked through your demo with 0.2.10 and 0.2.11, and the output is the same for both. Since transitioning with parameters is thoroughly unit tested, and very much a core feature of the library (for which, as you noted, there are no other bug reports), I strongly suspect this is not an issue related to UI Router.

@antmir
Copy link
Author

antmir commented Sep 4, 2014

I've meant that in plunkr my transitionTo just didn't change the state at all. perhaps I do have some mistake (which I can't find). anyway, on my real-project I do have the transitionTo+parameter issue...
I agree this is a core-feature and strangely I'm the only one reporting this (makes one think perhaps he isn't well :) ).
but I just can't otherwise explain it...
So if you want, you can close this and wait for the next reporter. I do think there is an issue.

@antmir
Copy link
Author

antmir commented Sep 4, 2014

I'll retry reproduce it in plunkr.
anyway, thx

@nateabele
Copy link
Contributor

I'll retry reproduce it in plunkr.

Yes, please. Btw, the state change also seemed to work fine. (Maybe just not as you expect, though?)

@antmir
Copy link
Author

antmir commented Sep 4, 2014

Can you please take a look at this:
http://plnkr.co/edit/d0aWYxYNd77q6KUApjP5?p=preview
?

With 0.2.10 after clicking the "click me to transition" you'll see the stateParams passed to transitionTo.
Please modify the script-importing to 0.2.11 (I couldn't find a link that worked for me, including copy-pasting http://angular-ui.github.io/ui-router/release/angular-ui-router.js. I assume I'm misunderstanding something). anyway, after moving to 0.2.11 see if the bug really happens (if I'm right you'll get: "Given State Params: {0:undefined, 1:undefined}")
Thx again

@roman-holovin
Copy link

.state('main.settings', {
            abstract: true,
            template: '<div ui-view></div>',
            url: '/settings'
        })
        .state('main.settings.management', {
            url: '/management',
            abstract: true,
            template: '<div ui-view="main"></div><div ui-view="modal"></div><div ui-view="confirmation"></div>'
        })
        .state('main.settings.management.list', {
            url: '',
            views: {
                'main': {
                    templateUrl: '...',
                    controller: '...',
                    resolve: {
                            ...
                    }
                }
            }
        })
        .state('main.settings.management.edit', {
            abstract: true,
        })
        .state('main.settings.management.edit.credentials', {
            params: ['id'],
            views: {
                'modal': {
                    templateUrl: '...',
                    controller: '...',
                    resolve: {
                        data:
                            ['$stateParams',
                            function($stateParams) {
                                console.log('fired');
                                console.log($stateParams);
                            }
                    }
                }
            }
        })

When I'm trying to move from "list" state to "edit.credentials" state via ui-sref="main.settings.management.edit.credentials({id: someId})", I've got {0: undefined} in $stateParams console.log.Is it bug or I'm trying to do something wrong here?

Update: When I call my parameter '0' instead of 'id', it works, but I'd rather use normal name for params

@nateabele nateabele reopened this Sep 6, 2014
@nateabele
Copy link
Contributor

Okay, there are two issues at play here. One is that uiSref now respects preventDefault(), and defers until after ngClick events have been processed. Since Angular prevents click events on a elements with no href, Angular itself is preventing the transition (it works if your "test" state has a URL).

Therefore: uiSref needs to be patched so that transitions to states without URLs ignore the first call to preventDefault().

Secondly (and this is a problem with your code using a feature that has been BC-broken), the format for params has gone from ['id','conversation'] to { id: {}, conversation: {} }`. Please update your code accordingly.

@christopherthielen
Copy link
Contributor

closing in lieu of #1362

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

4 participants