4

I'm trying to catch any changes in the select tag and activate a function if an option is selected.

html code:

<select [(ngModel)]="newProcurement.supplierNumber">
  <option (change)="findSupplierByNumber($event)"  *ngFor="let supplier of 
  allSuppliers" value="{{supplier.suplierName}}">{{supplier.suplierName}} 
  </option>

</select>

I'm trying to select a supplier and activate this function:

 findSupplierByNumber(ev){
 debugger;
 console.log(ev.target.value)
 }

function hasn't been activated for some reason , any suggestions ?

Bar Levin
  • 205
  • 1
  • 12
  • 4
    The `option` doesn't `change`, the `select` does. See the above question for the various choices you have for implementation. – Will Alexander Aug 11 '19 at 14:02

1 Answers1

2

Try binding the change event to the select instead of all the options. The change event is fired on the <select> element whenever an altercation of the value is committed by the user.Change your code to something like this:

 <select [(ngModel)]="newProcurement.supplierNumber" (change)="findSupplierByNumber($event)">
      <option *ngFor="let supplier of 
      allSuppliers" value="{{supplier.suplierName}}">{{supplier.suplierName}} 
      </option>
    </select>
iams0nus
  • 481
  • 3
  • 8