angularselectdefaultng-initngmodel

Default value for <select> using ng-input


Is there any way to set default value for select in my case without using controller?

I've tried many ways. This is the last one...

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

I need set "Select color" as default, and in the dropdown list will be empty string and items from library.


Solution

  • Find the answer. Maybe someone will need it...

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