2017-03-17 43 views
1

有没有什么办法可以在不使用控制器的情况下为select设置默认值?默认值为<select>使用ng-input

我试过很多方法。这是最后一个......

<select [(ngModel)]="model.carColour" [ngModelOptions]="{standalone: true}" class="form-control input-sm" ng-init="model.carColour='select'"> 
    <option value="select">Select color</option> 
    <option></option> 
    <option *ngFor="let item of carscolours" [value]="item.value"> {{item.text}}</option> 
</select> 

我需要设置“选择颜色”为默认值,并在下拉列表为空字符串,并从库项目。

+0

问题仍然存在 – Antatrix

回答

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> 
+0

谢谢! - 我一直在寻找这个! –

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

不起作用。我已经试过这个 – Antatrix

+0

我不明白那是行不通的。当你检查这个选项时,它没有这些属性吗?什么是违约? – Slime

+0

它工作,如果