state transition performed twice when using optional state parameters
When optional state parameters are defined for a state, the state transition is performed twice as long as the optional parameters.
The $stateParams of a controller that was called twice look like this: First: {offset: undefined, limit: undefined, sort: undefined, sortby: undefined} Second: {offset: 0, limit: 20, sort: "asc", sortby: "title"}
Note that all state parameters are optional and defined like this.
.state({
name: "list.products",
parent: "list",
url: "/products/:offset/:limit/:sortby/:sort/",
params: {
offset: { value: 0 },
limit: { value: 20 },
sort: { value: 'asc' },
sortby: { value: 'title' }
},
templateUrl: "views/partials/product-search-result-item.html",
controller: "ListProductsController"
})
When I use ui-sref without any parameter the controller is called twice. Products
Using all state parameters the controller is called only once. Products
IMHO this is a bug and I hope somebody can fix it as all controllers with optional parameters and API calls make API requests twice.
I think I've seen this as well. Will you please make a plunk?
Here is the plunkr: http://plnkr.co/edit/uQEznMA2fadSYQg3fCvc
As soon as I added the ID parameter to the URI (route1/:id) the controller is called twice
Here's what's happening:
- ui-sref calls
transitionTo transitionTowas not applying default params when buildingtoParams.transitionTocompletes and saves the partialtoParamsasfromParams- after the transition, the URL is sync'd.
- the sync code uses
UrlMatcherwhich applies default params, and calls transitionTo - normally, transitionTo exits early since the state and params are identical. However, in this case, the now
fromParams(step 3'stoParams) don't have defaults, while step 4's params have them, so the transition occurrs again.
patched plunk with fix from #1424 http://plnkr.co/edit/Wiej3lypbhPKFkAsRNoZ?p=preview
Thank you Chris for digging into that issue!
hi, i'm also experiencing this using routeProvider, '/page/:id?' has this fix also addressed routeProvider as well?
Hi, I'm seeing this when using version 0.2.13. Instead of using ui-sref I have am using ng-click to call a function which then calls $state.go(). I can also confirm this when using $state.transitionTo().
ng-click="selectAlert(alert)
var selectAlert = function(alert){ $state.go('app.alerts.list.detail', {alertId: alert.id}); }
Does this bug still exist or am I using this incorrectly?
I had same problem like @nolandubeau . version is 0.2.11. call $state.go in ng-click. some $state parameters are null.
Seems to be fixed in 0.2.14.
i am still getting the same problem in 0.2.15 ,is the problem fixed or still persist ,please help me with this one
I also am getting this problem in 0.2.15. I am using custom types in my solution.
Please make a plunker
+1, have the same problem in 0.2.15.
its working fine with 0.2.14,
Ok, nevermind, it was a problem of implementation of my login router. In fact I did it in my $stateChangeStart and it didn't end well. So I think I have to move this out in another listener.
I agree with @pranaydutta89; for me using version 0.2.14 instead if 0.2.15 fixes my issue. There does seem to be another issue here, which I am looking into.
@christopherthielen I have a Plunkr which demonstrates what I'm trying to do to make some sort of dynamic parameters work in 0.2.15. http://plnkr.co/edit/Yeex1Rmd1nWQvdrxj87N?p=preview. It works to change parameters syncronously, but not via a $timeout.
Im getting this problem in 0.2.15.
Using 0.2.14. fixed the problem to me.
+1 Same for me, I had to go back to 0.2.14 to fix the problem
+1 Same here
Actually it's also happening in the version 0.2.14 even though this version looks more stable than the 0.2.15.
Can confirm this for version 0.2.15. When using nested views and a parameter is present in ui-sref, then the parent resolve function is fired for a second time. Removing the parameter makes it work as expected.