我已经尝试在我的表单中添加多个角度验证器参数[即Validators.minLength(8)和Validators.maxLength(12)],我似乎无法得到它工作......这些参数被附加到下面代码中的(password和passwordc)实例。请帮忙吗?我如何在Angular 2表单中添加更多的Validator参数
export class signupComponent {
signupform: FormGroup;
constructor(public fb: FormBuilder) {
this.signupform = this.fb.group({
firstname: ['', Validators.required],
lastname: ['', Validators.required],
account: this.fb.group({
email: ['', Validators.required],
**password: ['', Validators.minLength(8), Validators.maxLength(12), Validators.pattern('[A-Za-z]{5}')],
passwordc: ['', Validators.minLength(8), Validators.maxLength(12), Validators.pattern('[A-Za-z]{5}')],
}, { validator: passwordMatcher }),**
shortbio: ['', Validators.required]
});
}
}
以前是这样,但不再是(IIRC:RC3或RC4)。现在,您可以简单地传递一个验证器数组 - 您不再需要'Validators.compose()'。然而,'Validator.compose()'*仍然可以被使用,所以我认为你的答案会解决这个问题。 – BlueM