我有一个选择:
<select id="position">
<option *ngFor='#contactType of contactTypes' [attr.value]='contactType.contactTypeId'>
{{contactType.description}}
</option>
</select>
我想根据条件选择一个选项:'contactType.contactTypeId == number' 而不使用 ngModel
最佳答案
我想这就是你想要的:
<select id="position">
<option *ngFor='#contactType of contactTypes'
[attr.value]='contactType.contactTypeId'
[attr.selected]="contactType.contactTypeId == number ? true : null">
{{contactType.description}}
</option>
</select>
要删除 selected
属性,您需要返回 null
(false
导致 selected="false"
).
关于html - Angular 2 在条件下选择了选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36750524/