如果索引值匹配,我正在尝试动态设置selected
属性。
<select class="form-control" disabled>
<option *ngFor="let agency of request.agencyList" [attr.selected]="request.agencyIndex == agency">{{agency}}{{request.agencyIndex}}
</option>
</select>
对象:
this.requests = [{
agencyList: ['Agency 1', 'Agency 2', 'Agency 3'],
agencyIndex: 1,
...
}]
但是,它将所有选项selected
属性设置为false
。
答案 0 :(得分:0)
我认为这就是你要找的东西:
<select class="form-control">
<option *ngFor="let agency of request.agencyList; let index=index;" [selected]="request.agencyIndex == index">
{{agency}}{{request.agencyIndex}}
</option>
</select>