我正在尝试使用[selected]和[ngValue]来设置表单中包含对象的select标签的默认值。但出于某种原因它们似乎不兼容。
示例代码:
<select id="selectedStore" *ngIf="showStore"
class="form-control"
formControlName="homeStore"
tabindex="{{getTabIndex('homeStore')}}">
<option *ngFor="let store of availableStores"
[ngValue]="store"
[selected]="store.storeId == personalInfo.homeStore?.storeId">
{{store.name}}
</option>
</select>
这段代码的默认值只会显示为空白。如果我删除 [ngValue],它可以正常工作,但选择的将是 store.name 值,而不是 store 对象。
您有什么建议吗?
[selected]与响应式表单无关。 - Günter Zöchbauer