我在 Angular 中制作了一个可重用的组件,我用它来构建多个表单,目的是提供一种快速修改多个数据项的方法。
我在这个组件中有 2 个输入字段,当使用 *ngFor 对数组进行迭代时,我通过输入属性进行绑定。一切都很好,并且可以很好地使用 id 并显示数据,但我遇到的问题是当我推动更新这两个字段的值时显示为“未定义”(除非我修改它们)。
我的标记是:
<input
#catTitle
matInput
placeholder="Document Title"
[value]="categoryTitle"
formControlName="categoryTitle"
[errorStateMatcher]="matcher"
>
我的后端是:
categoryForm = new FormGroup({
categoryTitle: new FormControl('', [Validators.minLength(3), Validators.maxLength(50)]),
categoryDescription: new FormControl('', [Validators.minLength(5), Validators.maxLength(200)])
})
我确定我错过了一些非常愚蠢的东西。