我需要在编辑时设置预选下拉列表。我正在使用反应形式。 检查我的代码:
答案 0 :(得分:1)
您将选项与[ngValue]="test.value"
绑定,但是在formGroup中设置了this.test [2]。
用valueTest : [this.test[2]]
替换valueTest : [this.test[2].value]
另外,将[ngValue]
替换为[value]
此外,您可以尝试执行此操作以检查操作正在进行:
compareObjects(o1: any, o2: any) {
console.log('o1 : ', o1);
console.log('o2 : ', o2);
return (o1===o2)
}
和
<select
class="form-control"
formControlName="valueTest"
[compareWith]="compareObjects"
>