我已经创建了我要检查密码确认它是否是有效的自定义验证属性:自定义的验证无法看到反应形式
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