-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Controller is instantiated multiple times when using date parameter #2484
Comments
Can you provide a plnkr example please? |
Here is a plnkr with angular 1.4.8 and ui-router 0.2.16. You can have a look in console for the output. |
Thanks. Verified this is a bug. We should only compare year month and day in .equals method. |
@christopherthielen I don't think that's the reason. I re-implemented the date type using var date = {
encode: function (date) {
if (!this.is(date)) {
return;
}
return [date.getFullYear(), ('0' + (date.getMonth() + 1)).slice(-2), ('0' + date.getDate()).slice(-2)]
.join('-');
},
decode: function (val) {
var match;
if (this.is(val)) {
return val;
}
match = this.capture.exec(val);
if (!match) {
return;
}
return new Date(match[1], match[2] - 1, match[3]);
},
is: angular.isDate,
equals: angular.equals,
pattern: /[0-9]{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[1-2][0-9]|3[0-1])/,
capture: /([0-9]{4})-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/
}; |
I added your date impl to the plunk and still see double transitions. |
This code fixes your plunker:
That equals method belongs here: |
Controller is instantiated multiple times when navigating to a state that uses a date parameter. If date parameter is optional controller is instantiated 3 times else twice.
This is my state definition:
P.s: I'm using 0.2.17 version
The text was updated successfully, but these errors were encountered: