我试图通过从后端传递值来设置下拉列表中的选定值。我可以为我想要的选项设置所选属性为true,但它不反映在UI上。 当我在浏览器中查看页面元素时,我可以看到它正确设置但可以在UI中看到任何标签。
<option value="2: Object" ng-reflect-ng-value="[object Object]" ng-reflect-selected="true">
模板:
<select class="form-control" id = {{id}} [(ngModel)]="bindModelData" (ngModelChange)="onSelectData($event)" [disabled]="disabled">
<option *ngFor="let object of objects" [ngValue]="object"
selected="{{object.description=== bindModelData?.description ?true:null}}>
{{object.description}}
</option>
</select>
设置后的UI元素:
<select class="form-control ng-untouched ng-pristine ng-valid" ng-reflect-model="[object Object]" ng-reflect-id="category" id="category">
<!--template bindings={
"ng-reflect-ng-for-of": "[object Object],[object Object],[object Object],[object Object],[object Object]"
}--><option value="0: Object" ng-reflect-ng-value="[object Object]">
AAA
</option><option value="1: Object" ng-reflect-ng-value="[object Object]" ng-reflect-selected="true">
BBB
</option><option value="2: Object" ng-reflect-ng-value="[object Object]">
CCC
</option><option value="3: Object" ng-reflect-ng-value="[object Object]">
DDD
</option><option value="4: Object" ng-reflect-ng-value="[object Object]">
EEE
</option>
</select>