2
我的項目中有2個對象:a company
和user
。我有一個表單,用戶可以更新他的個人資料。他可以更新的其中一件事是國家。現在顯示我使用下拉列表的國家。如果在Angular2中滿足條件,請在下拉列表中設置所選屬性
我想設置selected
屬性在其中country
的name
等於user
的實際country
的選項。 (country.name==user.country
)
這是我所嘗試過的,但它似乎沒有工作。
<select>
<option *ngFor="#c of countries" [ngStyle]="setStyles()" [ngValue]="c">{{c.name}}</option>
</select>
setStyles(){
let styles;
if (this.companies[i].name == this.user.country) {
styles = {
'selected'
}
return styles;
}
感謝它的作品,但不是每個用戶,但我想我需要調整我的一些代碼。 – Claudiu