如何使用反应形式设置预选下拉菜单?角度的

时间:2020-07-27 21:24:54

标签: javascript html angular typescript

我需要在编辑时设置预选下拉列表。我正在使用反应形式。 检查我的代码:

1 个答案:

答案 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"
>
相关问题