当从选择框中选择一个项目时,为什么没有调用组件类中的方法?

时间:2019-06-17 10:44:24

标签: angular

嗨,我有一个angular 5应用程序。我在组件模板html文件中有一个选择框,在组件类中有一个方法,当我们从下拉框中选择一个项目时,该方法将被调用。但是,它不起作用。请在下面找到代码

  <select formControlName="inventory" [compareWith]="compareInventory" change="inventoryChanged($event.target.value);">
          <option value="" disabled>{{ 'PLACEHOLDERS.SELECT_INVENTORY' | translate }}</option>
          <option *ngFor="let inventory of inventories" [ngValue]="inventory">{{ inventory.label }}</option>
        </select>

在组件ts文件中

  inventoryChanged(inventorySelected){
    console.log("inventory changed");
  }

我希望这个库存更改可以调用并将其记录到控制台中。但是我看不到任何东西登录到他的开发人员工具中。 感谢任何帮助

1 个答案:

答案 0 :(得分:1)

您得到了圆括号。因此您的绑定无法正常工作

  <select formControlName="inventory" [compareWith]="compareInventory" (change)="inventoryChanged($event.target.value);">
          <option value="" disabled>{{ 'PLACEHOLDERS.SELECT_INVENTORY' | translate }}</option>
          <option *ngFor="let inventory of inventories" [ngValue]="inventory">{{ inventory.label }}</option>
        </select>