[英]Angular 4 - ngfor with ngif error
我正在開發auglar 4項目,該數據是在選擇html中通過它在組件Loop中獲取的,但是我想根據它的名稱將特定選項標記為選中
碼
<select class="form-control" id="exampleSelect1">
<option *ngFor="let field of fields" *ngIf="field.name == 'Select me'; then selected='true'">{{field.name}}</option>
</select>
但是在ngfor中使用ngif時不起作用
錯誤
Error: Template parse errors:
Can't have multiple template bindings on one element. Use only one attribute named 'template' or prefixed with *
而不是ngIf
如果可以使用[selected] =“ field.name ==='Select me'”屬性來選擇
<select class="form-control" id="exampleSelect1">
<option *ngFor="let field of fields" [selected]="field.name==='Select me'">{{field.name}}</option>
</select>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.