Angular - Objects as Select Option Values Angular - Objects as Select Option Values typescript typescript

Angular - Objects as Select Option Values


It is the [compareWith] directive. Angular.io is down at the moment, so I will ink to this medium article for reference.

HTML

<mat-select      placeholder="Fruit"     [(ngModel)]="item.fruit"    [compareWith]="objectComparisonFunction">   <mat-option *ngFor="let option of options" [value]="option">{{option.label}}</mat-option></mat-select>

TypeScript

  public objectComparisonFunction = function( option, value ) : boolean {    return option.id === value.id;  }