I have the following code for a drop down list:
<select id="UnitOfMeasurementId" name="UnitOfMeasurementId" [(ngModel)]="UnitOfMeasurementId"> <option *ngFor="let unit of UnitOfMeasurements" [ngValue]="unit.Value" [selected]="unit.Selected">{{unit.Text}}</option> </select>
Each element of the UnitOfMeasurements array looks something like this:
Selected: false Text: "lb" Value: "1"
Or that:
Selected: true Text: "kg" Value: "3"
[(ngModel)]="UnitOfMeasurementId" contains the value of the item to be selected. In this particular example, this value is 3, so you need to select the 3rd element. Of course, when I check an element, it shows ng-reflect-selected="true" on the correct element, but nothing is selected. How can I get the correct item in the list for actual dynamic selection instead of adding the ng-reflect-selected="true" attribute?
source share