首页 > 解决方案 > 如何使用选择选项作为该函数的参数来调用更改选择选项的函数

问题描述

我想在选择值随角度参数变化时调用函数

<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>

我希望那些选择的选项价格和服务名称作为 checkCategory 函数的参数。有什么办法可以做到这一点。?

标签: javascriptangulartypescript

解决方案


您可能无法传递代码中编写的这些值,因为item, m, k它们不在范围内。相反,您可以传递$event给处理函数并使用它event.target.selectedOptions[0].parentElement来访问选定的 optGroup 元素。


推荐阅读