ngOptions "track by" makes copies of array elements, expected references #15980
Description
I'm submitting a ...
- bug report
- feature request
- other (Please do not submit support requests here (see above))
Current behavior:
Use of the track by
clause on a <select>
using ngModel
creates copies of elements/propertied from the source array/object. Changes to the ngModel
value are not reflected anywhere.
Expected / new behavior:
I expected changes to the ngModel value to propagate back to the source array/object.
Minimal reproduction of the problem with instructions:
https://embed.plnkr.co/ifB5nJ9wp8HUxzsSAi9G/
Select items from the list and attempt to edit the values in the box. No changes will take.
Angular version: 1.6.4
Browser: Chrome 58, IE 11
Anything else:
This is unexpected behavior to me. The documentation for both ngOptions
and ngRepeat
make no mention of this.
To accomplish a use-case like in the above-linked Plunker, one would currently need to write a lookup algorithm to find the model in the source array, and then apply the changes. Personally, I don't see what the concern is over the application mutating the selected object - I wouldn't think Angular developers would let even privileged users of a webapp modify the unique identifier of an object in a collection, instead let the XHR calls to the server handle creating unique IDs. But, I may have a limited perception here.
I feel this either needs to be documented, or it shouldn't be calling angular.copy
on selected items when track by
is in use.