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">
    {{animal.type}}
  </option>
</select>  

Define the compareWith method in your component :

  byAnimal(item1,item2){
  return item1.type == 'dog'
  }

The comparison that returns true becomes a selected option.

Here is a full plunker example :
https://plnkr.co/edit/AF9bHqtJON0KgnaTHUqa?p=preview