right way to call a function after selected option. Angular 4

Viewed 39619

Hello I need to call a function after one of the options is selected.

which is the best way to do it? im using angular4.

modo(){
  // if modo 1 is selected do something.
  // if modo 2 is selected do something.
  // if modo 3 is selected do something.
}
<label>Modo :</label>
<select id="selectid" class="form-control-mb-12">
   <option value="mod1">MODO 1</option>
   <option value="mod2">MODO 2</option>
   <option value="mod3">MODO 3</option>
</select>

5 Answers

In angular 4+ you should write select code like this

  <select [ngModel]="info" (onModelChange)="function()">
      <option [ngValue]="">select</option>
      <option *ngFor="info of infoSelect">{{info}}</option>
    </select>

This is the best way to call function on select

use (selectionChange) example:

<mat-select [(value)]="value" (selectionChange)="updateCategory()">
  <mat-option *ngFor="let name of names" [value]="name"> name </mat-option>
</mat-select>
Related