Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
/angular.jsPublic archive

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

Open
icholy wants to merge2 commits intoangular:master
base:master
Choose a base branch
Loading
fromicholy:master

Conversation

icholy
Copy link
Contributor

@icholyicholy commentedJan 5, 2017
edited
Loading

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 usetrackBy andselectAs together.

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

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

Does this PR introduce a breaking change?

No.

Please check if the PR fulfills these requirements

@icholyicholyforce-pushed themaster branch 2 times, most recently from52cde6c to4962888CompareJanuary 5, 2017 21:04
@Narretz
Copy link
Contributor

Narretz commentedJan 7, 2017
edited
Loading

So this is basically a shortcut for(val.id || val.subItem.id)? But in which cases exactly do you need this?
From your changes to the docs, that's not entirely clear, so I would like a better description of this feature.
It's also not enough to change the existing tests, there should be new tests that make explicit what this feature does.

@icholy
Copy link
ContributorAuthor

icholy commentedJan 7, 2017
edited
Loading

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 thetrack by expression was(item.valueOf() || item.subItem.valueOf()) and that wont work because all objects have that method.

@icholy
Copy link
ContributorAuthor

@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
ContributorAuthor

icholy commentedJan 26, 2017
edited
Loading

@Narretz I've add a bit more to the documentation, but I'm not sure about the tests. Here's what it says above the tests I changed.

  /**   * This behavior is broken and should probably be cleaned up later as track by and select as   * aren't compatible.   */

This is what the$value variable aims to fix. So it doesn't make sense to still have these tests using the hacky workaround. If I was going to add tests, they would be identical except for how thetrack by expression is written.

Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers
No reviews
Assignees
No one assigned
Projects
None yet
Milestone
Ice Box
Development

Successfully merging this pull request may close these issues.

3 participants
@icholy@Narretz@googlebot

[8]ページ先頭

©2009-2025 Movatter.jp