我正在使用Angular2 ForumBulder创建表单并添加验证 . 下面是组件的示例代码
this.OtpForm = this._fb.group({
otpInput: this._fb.group({
otpInput1: ['', Validators.required],
otpInput2: ['', Validators.required],
otpInput3: ['', Validators.required],
}, { validator: this.numericValidator })
});
现在这很好用 . 但问题是如何 Validators.required
如同自定义验证器 numericValidator
一样对所有字段都是通用的?
1 回答
例如,您可以为otpInput组创建一个自定义验证器
并添加到这个:
使用Validators.compose()组合验证器
用于异步验证器使用