feat(ngOptions): add $value variable for easier use of trackBy+selectAs by icholy · Pull Request #15584 · angular/angular.js · GitHub
Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

feat(ngOptions): add $value variable for easier use of trackBy+selectAs#15584

Open
icholy wants to merge 2 commits intoangular:masterfrom
icholy:master
Open

feat(ngOptions): add $value variable for easier use of trackBy+selectAs#15584
icholy wants to merge 2 commits intoangular:masterfrom
icholy:master

Conversation

@icholy
Copy link
Copy Markdown
Contributor

@icholy icholy commented Jan 5, 2017

What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)

Feature.

What is the current behavior? (You can also link to an open issue here)

Currently it's a pain to use trackBy and selectAs together.

What is the new behavior (if this is a feature change)?

It introduces a $value variable which simplifies how the trackBy expression can be written.

Does this PR introduce a breaking change?

No.

Please check if the PR fulfills these requirements

@icholy icholy force-pushed the master branch 2 times, most recently from 52cde6c to 4962888 Compare January 5, 2017 21:04
@Narretz
Copy link
Copy Markdown
Contributor

Narretz commented Jan 7, 2017

@icholy
Copy link
Copy Markdown
Contributor Author

icholy commented Jan 7, 2017

So this is basically a shortcut for (val.id || val.subItem.id)?

In the simple case, yes.

But in which cases exactly do you need this?

Here's a contrived example (note the id's don't match up).

$scope.items = [{
  id: 0,
  label: 'aLabel',
  subItem: { name: 'aSubItem', id: 1 }
}, {
  id: 1,
  label: 'bLabel',
  subItem: { name: 'bSubItem', id: 0 }
}];

$scope.selected = $scope.items[0].subItem;

If you use (val.id || val.subItem.id) here, the wrong object will be initially selected.

demo: https://plnkr.co/edit/8MQXJpRqEdtwF1hcCM3w?p=preview

edit: In my actual use case the track by expression was (item.valueOf() || item.subItem.valueOf()) and that wont work because all objects have that method.

@icholy
Copy link
Copy Markdown
Contributor Author

icholy commented Jan 7, 2017

@Narretz I noticed you put this in the Ice Box milestone and I don't want to invest more time into this if it's not going anywhere. I think that I presented a valid use case in my last comment, but if that's not the case, let me know so I don't waste my time.

@icholy
Copy link
Copy Markdown
Contributor Author

icholy commented Jan 26, 2017

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.

3 participants