我不确定这是否是预期的行为;我有以下内容:
this.formGroup = this.fb.group({
name: this.fb.group({
firstName: ['', Validators.required],
lastName: ['', Validators.required]
})
});
<div formGroupName="name">
<input type="text" formControlName="firstName">
<input type="text" formControlName="lastName">
</div>
当我提交表单并console.log(this.formGroup)
时,errors
name
的{{1}}对象为空。我预计它应该AbstractControl
Object
。我哪里错了?
答案 0 :(得分:1)
感谢@yurzui指出相关的issue - 这是一种解决方法,只需检查两个控件:
name: this.fb.group({
firstName: ['', Validators.required],
lastName: ['', Validators.required]
}, {validator: nameValidator}),
当然,这需要明确包含在验证器中:
{{1}}