X Tutup
Skip to content

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

Closed
kara wants to merge 1 commit intoangular:masterfrom
kara:trackBy
Closed

feat(ngFor): add custom trackBy function support#6779
kara wants to merge 1 commit intoangular:masterfrom
kara:trackBy

Conversation

@kara
Copy link
Copy Markdown
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
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown

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

@johnpapa
Copy link
Copy Markdown
Contributor

johnpapa commented Feb 3, 2016

linking to the new issue #6872

@johnpapa johnpapa mentioned this pull request Feb 3, 2016
@kara kara deleted the trackBy branch October 13, 2018 01:08
@angular-automatic-lock-bot
Copy link
Copy Markdown

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

X Tutup