我已經創建了我要檢查密碼確認它是否是有效的自定義驗證屬性:自定義的驗證無法看到反應形式
static cannotContainSpace(control: AbstractControl) : ValidationErrors | null{
console.log('----- control', control.get('password'));
console.log('----- control', control.get('passwordConfirmation'));
if((control.value as string).indexOf(' ') >= 0){
return {cannotContainSpace : true}
}
return null;
}
你能告訴我,爲什麼在那些控制檯日誌,我得到所有的時間都是空值?我的形式是通過建立和reactive form
看起來像:
form = new FormGroup({
login: new FormControl('', [Validators.required, Validators.email]),
password: new FormControl('',
[
Validators.required,
Validators.minLength(3),
PasswordValidators.cannotContainSpace
]),
passwordConfirmation: new FormControl('', [Validators.required])
});
但不是你的驗證工作,雖然? – amal
它的工作原理,因爲在控制檯我得到這個陳述'----控制',但後面是'空' – bielas
@amal看到更新 – bielas