【发布时间】:2018-02-05 01:56:05
【问题描述】:
这是我在 app.component.html 中循环的模拟数据数组
questions: [
{question: 'Question-1'},
{question: 'Question-2'},
{{question: 'Question-3'}
]
在我的 app.component.ts 中,如下所示,由于我使用的是响应式表单方法,我已经实例化了表单组并声明了一个名为“note”的 formControl,它是按要求声明的:
导出类示例 {
regPresentationForm: FormGroup;
this.regPresentationForm = new FormGroup ({
note: new FormControl(null, Validators.required),
});
}
在我的 HTML 组件中,我循环遍历数组并显示文本字段,因此将有三个文本框,每个文本框都有 note 作为我的 formControl:
<ng-container *ngFor = "let question of questions">
<textarea type="text" id="textArea" placeholder="Enter the Note" class="form-control" formControlName = "note">
</textarea>
</ng-container>
由于需要注释表单控件,因此我将禁用提交按钮,如下所示:
<button class="btn btn-primary" type="submit"[disabled] = "!regPresentationForm.valid">
Save & Continue
</button>
问题:
问题是,如果我在第一个文本框中输入文本,表单会变得有效,因此 Angular 将其视为重复三次的单个框,这不应该发生,它应该单独考虑每个注释字段(注释 formcontrol 的 3 个实例,因为迭代完成三次)
不知道如何解决这个需要帮助。
我希望我很清楚。
【问题讨论】:
标签: angular5 angular-reactive-forms