How to call function on Change of select option with select option as a parameters of that function

Viewed 153

i want to call function when select value change with the parameters in angular

<div class="col-sm-6 col-md-4">
  <label class="mobileNumberLabel " for="mobilrNumber">Select Service</label>
  <div class="nice-wrap">
     <select (change)="checkCategory(item.price,item.serviceName,m,k,'add');" class="js-example-basic-single nice-textbox" >
       <optgroup *ngFor="let item of serviceObject;let k = index" label='{{item.categoryName}}'>
          <option *ngFor="let service of item.services;let m = index">
            {{service.serviceName}} -&nbsp;&nbsp;{{item.categoryName}}
          </option>
       </optgroup>
     </select>
   </div>
</div>

i want those selected option price and serviceName as a parameter of checkCategory function. is there any way to do this one. ?

1 Answers

You may not be able to pass these values as written in your code, as item, m, k are not in scope. Instead, you can pass $event to the handler function and use event.target.selectedOptions[0].parentElement to access the selected optGroup element.

Related