-
Notifications
You must be signed in to change notification settings - Fork 27.5k
docs(ngOptions): explain using 'select as' and 'track by' together #13007
Conversation
I (obviously) like documenting that it is possible to use |
Thanks @ryanhart2 and @gkalpak for working on this. |
I tried to incorporate the original example with the two new examples, but the results are pretty confusing: http://plnkr.co/edit/GBw4YXl3sDzkX8oqXR4s?p=preview I feel that the example needs to be much clearer in which circumstances the examples will work and in which not. The new "wrong" example works if you only change the selection from th UI, but the problem with the track by expression only occurs when the model is preselected. So this part of the original explanation is completely lost. I think it would be the best if we had an actual runnable example where you could manipulate the selects and set the model the different values. |
* change warning to indicate that 'select as' and 'track by' can be used together with care * provide an example that will work and an example that will not work * provide a simple explanation of why the non-working example does not work
* selected" option. | ||
* In both examples the **`track by`** expression is applied successfully to each `item` in the `items` array. | ||
* Because the selected option has been set in code, the **`track by`** expression is also applied to the `ngModel` | ||
* value. In the first example, the `ngModel` value is `item[x]` and the **`track by`** expression evaluates to |
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.
item[x] --> items[x]
@Narretz, wrt #13007 (comment), I don't get what you mean. What is the confusing part ? I can see the problem happening when the When the value is set via the Do I miss something ? |
/ping @Narretz |
Go for it @gkalpak |
Sorry for the delay, I'm checking this again, give me 10 minutes. |
* a wrong object, the selected element can't be found, `<select>` is always reset to the "not | ||
* selected" option. | ||
* In both examples the **`track by`** expression is applied successfully to each `item` in the `items` array. | ||
* Because the selected option has been set in code, the **`track by`** expression is also applied to the `ngModel` |
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.
"has been set in code" doesn't really tell me anything. How about "has been set from the scope"?
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'll change it to "has been set programmatically in the controller". How about that ?
Apart from a minor nitpick, it's looking good now. |
…by` together Changes: * Modify warning message to indicate that `track by` can be used with `select as`, but subject to certain limitations. * Provide both a working and an non-working example. * Explain why the latter does not work. Closes #13007
Tweaked a bit and merged. Also backported to |
👍 for merging. Technically I don't think there needs to be a
|
Fixes #11768