Issue
I am using angular5. I want to make a option selected as default. But when I use the ngModel directive my code does not work anymore.
here is my code:
<select class="form-control" [ngModelOptions]="{standalone: true}" [(ngModel)]="singleCar">
<option value="null" selected='true' disabled>select car </option>
<option [ngValue]="Car" *ngFor="let car of allCars">{{singleRole.name}}</option>
</select>
does someone have a solution?
thx guys!
Solution
You have to do this in the html:
<option [ngValue]="null">Select a car</option>
and in your component, you have to specify that the default value is null.
This works:
singelCar = null;
This does not:
singleCar;
Answered By - Kuiken
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.