我已經嘗試在我的表單中添加多個角度驗證器參數[即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