Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

fix(select): Add exception for unsupported ngOptions use case #9290

Closed
wants to merge 1 commit into from

Conversation

janv
Copy link

@janv janv commented Sep 26, 2014

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.

Part 2 of the split of #8544 as requested by @btford

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}')",
Copy link
Contributor

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!?)"

Copy link
Author

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?

Copy link
Contributor

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.

@caitp caitp added this to the 1.3.0 milestone Sep 26, 2014
@caitp
Copy link
Contributor

caitp commented Sep 26, 2014

honestly looking at the test case I would just consider the current behaviour a bug, it doesnt make sense to throw here

@janv
Copy link
Author

janv commented Sep 27, 2014

The original patch did have a valid and useful point.
When I got to work on this, I actually tried finding a way to make this behave in a sane way but I couldn't figure out how at the time.
I could give it another try. This is a bit tricky though and will take some more time.

@jeffbcross
Copy link
Contributor

@btford mind taking this one since you're working on the corresponding PR/Issue?

@jeffbcross jeffbcross modified the milestones: 1.3.0, 1.3.0-rc.4 Sep 30, 2014
@jeffbcross
Copy link
Contributor

Thanks for submitting this. @caitp is right that we should fix the underlying issue: support track-by with complex expressions. I'm going to close this and leave the original issue open, and will work on a fix.

@jeffbcross jeffbcross closed this Sep 30, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants