Angular 在同一对象中传递表单字段值

Angular 在同一对象中传递表单字段值,angular,Angular,我正在尝试向自定义表单验证程序发送值: this.myForm = this.fb.group({ Id: [null], Password: ['', [Validators.required]], PasswordConfirm: ['', Validators.compose([CustomValidators.expectedMatchingFields(this.myForm.controls.Password.v

我正在尝试向自定义表单验证程序发送值:

this.myForm = this.fb.group({
            Id: [null],
            Password: ['', [Validators.required]],
            PasswordConfirm: ['', Validators.compose([CustomValidators.expectedMatchingFields(this.myForm.controls.Password.value), Validators.required])]
        });
但它不喜欢我发送这个.myForm.controls.Password.value。还有别的办法吗


表示无法读取未定义的属性“controls”时出错。

this.myForm在调用时为null

CustomValidators.expectedMatchingFields(this.myForm.controls.Password.value)
在调用this.fb.group之前,无法执行此操作。 我的建议是:在没有这个验证器的情况下创建表单,然后更新它,如前所述

我想这可能有用

this.myForm = this.fb.group({
 Id: [null],
 Password: ['', [Validators.required]],
 PasswordConfirm: ['']
})


你说不喜欢我送是什么意思?是否引发了任何错误?您能否提供更多信息,如什么错误或验证器是如何实现的
this.myForm.controls.PasswordConfirm
.setValidators(
Validators.compose(
[CustomValidators.expectedMatchingFields(
  this.myForm.controls.Password.value),
  Validators.required
]));