Skip to content

trackBy in *ngFor not working in <select>?  #13828

Closed

Description

@joostvandoremalen

I'm submitting a ...

[x] bug report => search github for a similar issue or PR before submitting

Current behavior
When using ngModel and trackBy in <select> the initial value is not selected when it is an object.

Expected behavior
Initial value should be selected.

Minimal reproduction of the problem with instructions
HTML:

<select [(ngModel)]="selectedItem">
    <option *ngFor="let item of items; trackBy:itemIdentity" [value]="item">
      {{item.name}}
   </option>
</select>

TS:

private items = [{id: 0, name: 'first'}, {id: 1, name: 'second'}];
private selectedItem = {id: 1, name: 'second'};

itemIdentity(index:number, item:any):any {
   return item.id;
}
  • Angular version: 2.4.1
  • Browser: Chrome
  • Language: TypeScript X.X

Activity

  1. DzmitryShylovich commented on Jan 7, 2017

    @DzmitryShylovich
    Contributor

    Select doesn't use trackBy function from ngFor for comparing options.
    Duplicate of #13268

  2. DzmitryShylovich commented on Feb 1, 2017

    @DzmitryShylovich
    Contributor
  3. pkozlowski-opensource commented on Feb 1, 2017

    @pkozlowski-opensource
    Member

    Fixed via f89d004, thnx @DzmitryShylovich

  4. angular-automatic-lock-bot commented on Sep 10, 2019

    @angular-automatic-lock-bot

    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.

  5. locked and limited conversation to collaborators on Sep 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions