【发布时间】:2016-05-17 15:24:22
【问题描述】:
我的项目中有 2 个对象:company 和 user。我有一个表格,用户可以在其中更新他的个人资料。他可以更新的一件事是国家。现在要显示我使用下拉列表的国家/地区。
我想在country 的name 等于user 的实际country 的选项中设置selected 属性。 (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;
}
【问题讨论】:
标签: forms drop-down-menu angular ng-style