-
Notifications
You must be signed in to change notification settings - Fork 27.4k
perf(ngOptions): only perform deep equality check on ngModel if using track by #11448
perf(ngOptions): only perform deep equality check on ngModel if using track by #11448
Conversation
@@ -1657,7 +1701,7 @@ describe('ngOptions', function() { | |||
scope.values.pop(); | |||
}); | |||
|
|||
expect(element.val()).toEqual(''); | |||
expect(element.val()).toEqualUnknownValue(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wish I had a better understanding of unknownValue
usage in select + options. Had to revert the spec back to its form in ef894c8.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, so the reason for this is that, if the model is null
then element.val()
is empty but if the model contains a value that doesn't match any option then element.val()
is '?'
.
When we remove the option the value becomes invalid so we get '?'
but then the model is cleared out and becomes null
. If we have a watch on the model then this will cause the ngModel
to run $render
, which update the element value to ''
.
I think that what we need is to trigger a new call to $render
when the selected option is removed...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually what we need to do is fix the bit of code inside updateOptions
(https://github.com/angular/angular.js/pull/11448/files#diff-0a9e86a58b2663074f51454f7a18a0efR646) that checks if the model has changed
I'll take a better look over the weekend but I think this is good. |
👍 |
* array of objects. See an example [in this jsfiddle](http://jsfiddle.net/qWzTb/). | ||
* **Note:** By default, `ngModel` compares by reference, not value. This is important when binding to an | ||
* array of objects. See an example [in this jsfiddle](http://jsfiddle.net/qWzTb/). When using `track by` | ||
* in an `ngOptions` expression, however, equality checks will be performed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I might add deep (equality) or something, to make it more clear.
(Technically, even in the default case, it is checking for equality (by reference).)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point! updated in rebased commit below.
👍 |
1 similar comment
👍 |
Thanks @booleanbetrayal for this |
np ... thanks @petebacondarwin ! |
… track by Closes angular#11448 Closes angular#11447
Closes #11447