mis*_*hap 11 html select angular
我有一个选择:
<select id="position">
<option *ngFor='#contactType of contactTypes' [attr.value]='contactType.contactTypeId'>
{{contactType.description}}
</option>
</select>
Run Code Online (Sandbox Code Playgroud)
我想条件选择一个选项:' contactType.contactTypeId == number '而不使用ngModel
Gün*_*uer 26
我想这就是你想要的:
<select id="position">
<option *ngFor='#contactType of contactTypes'
[attr.value]='contactType.contactTypeId'
[attr.selected]="contactType.contactTypeId == number ? true : null">
{{contactType.description}}
</option>
</select>
Run Code Online (Sandbox Code Playgroud)
要selected删除属性,您需要返回null(false结果selected="false").