Reputation: 8505
I have a select:
<select id="position">
<option *ngFor='#contactType of contactTypes' [attr.value]='contactType.contactTypeId'>
{{contactType.description}}
</option>
</select>
I would like to have a selected option on condition: 'contactType.contactTypeId == number' without using ngModel
Upvotes: 15
Views: 24311
Reputation: 657058
I guess this is what you want:
<select id="position">
<option *ngFor='#contactType of contactTypes'
[attr.value]='contactType.contactTypeId'
[attr.selected]="contactType.contactTypeId == number ? true : null">
{{contactType.description}}
</option>
</select>
To get the selected
attribute removed you need to return null
(false
results in selected="false"
).
Upvotes: 35