Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ngFor): add custom trackBy function support #6779

Closed
wants to merge 1 commit into from

Conversation

kara
Copy link
Contributor

@kara kara commented Jan 29, 2016

Make it possible to track items in iterables in custom ways (e.g. by ID or index), rather than simply by identity.

Usage:

With template element:

@Component(
  template: `
   <template ngFor #item [ngForOf]="items" [ngForTrackBy]=customTrackBy">
      {{item}}
   </template>
   `
)
class MyComponent {
  customTrackBy(index: number, obj: any): any {
    return index;
  }
}

With *ngFor:

@Component(
  template: `
   <div *ngFor="#item of items; trackBy:customTrackBy">
      {{item}}
   </div>
   `
)
class MyComponent {
  customTrackBy(index: number, obj: any): any {
    return index;
  }
}

@mhevery Did you want to review this?

Closes #4402

@kara kara force-pushed the trackBy branch 7 times, most recently from 9c10d95 to 675bb1c Compare January 31, 2016 03:30
@kara kara added action: review The PR is still awaiting reviews from at least one requested reviewer and removed state: WIP labels Jan 31, 2016
@kara kara force-pushed the trackBy branch 2 times, most recently from 88e3628 to 6771d46 Compare February 1, 2016 20:27
@@ -42,6 +43,10 @@ export class DefaultIterableDiffer implements IterableDiffer {
private _removalsHead: CollectionChangeRecord = null;
private _removalsTail: CollectionChangeRecord = null;

constructor(private _trackByFn?: TrackByFn) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you do _trackByFn: TrackByFn = trackByIdentity instead? Try to do this if ts2dart supports it. If not, what you have is good.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's what I wanted to do too :) It doesn't seem to be supported.

@vsavkin vsavkin added pr_state: LGTM and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Feb 1, 2016
@vsavkin vsavkin added the action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews label Feb 1, 2016
@kara kara force-pushed the trackBy branch 2 times, most recently from 788420c to 26b72a4 Compare February 2, 2016 02:31
    Make it possible to track items in iterables in custom ways (e.g. by ID or index), rather than simply by identity.
@kara kara added action: merge The PR is ready for merge by the caretaker and removed action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews labels Feb 2, 2016
@mary-poppins
Copy link

Merging PR #6779 on behalf of @alexeagle to branch presubmit-alexeagle-pr-6779.

@johnpapa
Copy link
Contributor

johnpapa commented Feb 3, 2016

linking to the new issue #6872

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 14, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[ngFor] trackby equivalent ?
6 participants