使用ng-input的<select>的默认值

时间:2017-03-17 16:55:51

标签: angular select default ng-init ngmodel

有没有办法在不使用控制器的情况下为我的情况设置select的默认值? 我尝试了很多方法。这是最后一个...... &lt; select [(ngModel)] =&#34; model.carColour&#34; [ngModelOptions] =&#34; {standalone:true}&#34; class =&#34; form-control input-sm&#34; NG-INIT =&#34; model.carColour =&#39;选择&#39;&#34;&GT;      &lt; option value =&#34;选择&#34;&gt;选择颜色&lt; /选项&gt;      &LT;选项&GT;&LT; /选项&GT;      &lt; option * ngFor =&#34;让carscolours&#34; [值] =&#34; item.value&#34;&GT; {{item.text}}&LT; /选项&GT;  &LT; /选择&GT; 我需要设置&#34;选择颜色&#34;默认情况下,在下拉列表中将是空字符串和库中的项目。

2 个答案:

答案 0 :(得分:2)

找到答案。也许有人需要它......

<select [(ngModel)]="model.carColour"  #States="ngModel" name="carColours" class="form-control input-sm" >
       <option [ngValue]="model.carColour" hidden>Please, select...</option>
       <option></option>
       <option *ngFor="let item of carscolours" [ngValue]="item.value" >{{item.text}}</option>
    </select>

答案 1 :(得分:0)

<option selected="selected">Select Color</option>