There are several questions about this and different answers but none of them really answers the question. So again:
Setting default of a Dropdown select by value isn't working in my case. Why?
This is from the dynamic Form tutorial of Angular 4:
<select [id]="question.key" [formControlName]="question.key">
<option *ngFor="let opt of question.options" [value]="opt.key" [selected]="opt.selected">{{opt.selected+opt.value}}</option>
</select>
It doesn't select anything. Available options are:
- trueaaa
- falsebbb
- falseccc
But static true:
<option ... [selected]="true">...</option>
selects the last value (all true).
It also works with a private variable boolvar = true
and using it in [selected]="boolvar"
I don't understand the difference between the "opt" object and the class variable.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…