私のプロジェクトには、 acompany
と an の2 つのオブジェクトがありuser
ます。ユーザーが自分のプロフィールを更新できるフォームがあります。彼が更新できるものの 1 つは国です。ここで、ドロップダウン リストを使用して国を表示します。
の が の実際のと等しい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;
}