Angular 4 compareWith Option Selector

Angular introduced a handy directive to help you compare options to select. Lets see how this directive works. Add this directive to your select :

<select [compareWith]="byAnimal" [(ngModel)]="selectedAnimal">  
  <option *ngFor="let animal of animals" [ngValue]="animal">

Define the compareWith method in your component :

  return item1.type == 'dog'

The comparison that returns true becomes a selected option.

Here is a full plunker example :