【发布时间】:2020-11-11 21:34:01
【问题描述】:
大家好,我是 Angular 新手,所以我很难处理 Angular 中一些非常常见的事情。我正在使用一种反应形式,其中我使用了一些选择标签,一切都很顺利,除非我尝试从选择标签中预先选择一个选项,其中的数据来自其余调用,选择标签没有设置向上。为了清楚起见,我使用 formGroup patchValue 来填充所有控件的值。
this.contactForm.patchValue(this.contractOwner);
下面是我的选择标签的样子
<select formControlName="contractCategory" class="form-control">
<option [ngValue]="null" selected>Please choose</option>
<option *ngFor="let category of contactCategoryList" [ngValue]="category">
{{ category.description }}
</option>
</select>
下面是从 rest 调用中选择的值对象来了
contractCategory: {id: 2, code: "C2", description: "Category 2", organizationId: 0, isActive: 1,…}
【问题讨论】:
-
你能在这里添加你的打字稿文件吗?
-
很可能是 stackoverflow.com/questions/61466116/… 的副本。
select需要compareWith来根据 id 比较类别。
标签: angular drop-down-menu angular-reactive-forms