首页 > 解决方案 > 如何在 Angular 2 的下拉菜单中使用两种方式绑定概念?

问题描述

我怀疑如何在我尝试过的下拉按钮中使用两种方式绑定概念,但它不起作用。

标签: angularangular2-routingangular2-templateangular2-formsangular2-directives

解决方案


两种方式绑定意味着您只需要[(ngModel)]在代码中使用这样的变量绑定(如果需要,您可以像使用 as 一样在模板中使用局部变量#businesstype,否则将其删除) -

<select class="form-control" id="business_type" required [(ngModel)]="update.business_type" name="business_type">
  <option disabled>Select</option>
  <option *ngFor="let user of users" [value]="user.id">{{user.method}}</option>>
</select>

带有演示条目的工作示例


推荐阅读