如何在带有字符串数组的select控件上进行默认选择。
这有效:
<select class="form-control"
[ngModel]="defaultSubscription"
name="subscription">
<option value="Basic">Basic</option>
<option value="Advanced">Advanced</option>
<option value="Pro">Pro</option>
</select>
&#13;
但这个不是:
<select class="form-control"
[ngModel]="defaultSubscription"
name="subscription">
<option *ngFor="let subsciption of subscriptions"
value="{{subscription}}">
{{subsciption}}
</option>
</select>
&#13;
答案 0 :(得分:2)
使用方括号
let subscriptions = ['subscription1', 'subscription2'];
<select class="form-control"
[ngModel]="defaultSubscription"
name="subscription">
<option *ngFor="let subsciption of subscriptions"
[value]="subscription">
{{subsciption}}
</option>
</select>
答案 1 :(得分:1)
只需删除value
即可按您的意愿工作,此处不需要:
<select class="form-control"
[ngModel]="defaultSubscription"
name="subscription">
<option *ngFor="let subsciption of subscriptions">{{subsciption}}</option>
</select>