我有一个选择下拉列表的以下代码:
<select id="UnitOfMeasurementId" name="UnitOfMeasurementId" [(ngModel)]="UnitOfMeasurementId"> <option *ngFor="let unit of UnitOfMeasurements" [ngValue]="unit.Value" [selected]="unit.Selected">{{unit.Text}}</option> </select>
UnitOfMeasurements数组中的每个项看起来像这样:
Selected: false Text: "lb" Value: "1"
或这个:
Selected: true Text: "kg" Value: "3"
[(ngModel)] =“UnitOfMeasurementId”包含应选择的项的值.在此特定示例中,该值为3,因此应选择第3个项目.果然,当我检查元素时,它在正确的项目上显示ng-reflect-selected =“true”,但实际上没有选择任何内容.如何才能获得列表中的正确项目以实际动态选择而不是仅添加ng-reflect-selected =“true”属性?