-
Notifications
You must be signed in to change notification settings - Fork 27.4k
fix(select): Add exception for unsupported ngOptions use case #9290
Conversation
ngOptions introduced `track by` in c32a859. Using `track by` puts constraints on the value you can use in the interpolation expression in ngOptions. This patch adds an exception if you use ngOptions in an unsupported way.
@@ -338,6 +338,12 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) { | |||
// - optionGroupsCache[?][0] is the parent: either the SELECT or OPTGROUP element | |||
optionGroupsCache = [[{element: selectElement, label:''}]]; | |||
|
|||
if (track && match[2] && valueName !== match[1]) { | |||
throw ngOptionsMinErr('trackSelect', | |||
"Do not use 'track by' when your select ('{0}') is different from your value ('{1}')", |
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.
as an english speaker, I have no idea what this error message is telling me. "Do not use 'track by' when your select (what is "my select"?) is different from your value (??? what!?)"
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.
Those are the terms used in the documentation to describe the different parts of the ng-options expression (see https://docs.angularjs.org/api/ng/directive/select).
I'm not too happy about the wording either. The insertion of the actual parsed subexpression should make clear what is meant though. Would you be ok with putting select
and value
in quotes?
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 would rather we didn't have this limitation in the first place and just made this work the way people expect it to work.
honestly looking at the test case I would just consider the current behaviour a bug, it doesnt make sense to throw here |
The original patch did have a valid and useful point. |
@btford mind taking this one since you're working on the corresponding PR/Issue? |
Thanks for submitting this. @caitp is right that we should fix the underlying issue: support |
ngOptions introduced
track by
in c32a859.Using
track by
puts constraints on the value you can use in the interpolationexpression in ngOptions. This patch adds an exception
if you use ngOptions in an unsupported way.
Part 2 of the split of #8544 as requested by @btford