首页 > 解决方案 > 使用 ngModel、ngFor 和 Angular dropDownList

问题描述

我已经建立了这两个下拉列表:
在此处输入图像描述

使用此 html 代码:

<div class="form-group">
  <select  name="dropDownList1" class="form-control form-control-sm">
  <option *ngFor="let s of list_of_Values;"  id="field_status" name="field_status"   >{{s}}</option>
</select>
<select  name="dropDownList2" class="form-control form-control-sm">
  <option *ngFor="let s of list_of_Values;"  id="field_status" name="field_status"   >{{s}}</option>
</select>
</div>

这个打字稿代码:

list_of_Values:string[]=['value1','value2','value3','value4']
  list_of_Chosen_Values:string[]=['chosenValueOfList1','chosenValueOfList2']

我想做的是使用

模型

在选项标签内:

  <option *ngFor="let s of list_of_Values;"  id="field_status" name="field_status"   >{{s}}</option>

绑定 的值:

  list_of_Chosen_Values:string[]=['chosenValueOfList1','chosenValueOfList2']

用户在两个列表中选择的值。
这甚至可行吗?

标签: angularbootstrap-4ngforangular-ngmodelngmodel

解决方案


推荐阅读