我的项目中有 2 个对象:acompany
和user
. 我有一个表格,用户可以在其中更新他的个人资料。他可以更新的一件事是国家。现在要显示我使用下拉列表的国家/地区。
我想selected
在选项中设置属性,其中 的name
等于country
实际country
的user
。( 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;
}