我想根据ID在下拉列表中显示选定的项目。
<div class="formrow" *ngFor='let a of applicantName'>
<label>Status Selection :</label>
<select id="AStatus" formControlName="AStatus" class="form-control">
<option value="0">All</option>
<option *ngFor="let apt of applicantStatus" [value]="apt.ApplicantStatusID" [selected]="apt.ApplicantStatusID === a.Status">
{{ apt.ApplicantStatus }}
</option>
</select>
</div>
此代码不起作用,并且未显示所选选项。
答案 0 :(得分:1)
value
应该设置为select not for option。
<div class="formrow" *ngFor='let a of applicantName'>
<label>Status Selection :</label>
<select id="AStatus" [value]="apt.ApplicantStatusID" formControlName="AStatus" class="form-control">
<option value="0">All</option>
<option *ngFor="let apt of applicantStatus" [value]="apt.ApplicantStatusID">
{{ apt.ApplicantStatus }}
</option>
</select>
</div>