Angularjs   发布时间:2022-04-20  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了angular – Async Validator Throw Expected validator返回Promise或Observable大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图用密码值确认密码.我按照Async验证器标准完成了.但我想知道它没有工作,并给我以错误.请告诉任何人如何解决错误.

这是我的代码.

呼叫验证器:

cPass: ['',Validators.compose([
  Validators.required,Validators.maxLength(32),Validators.minLength(10)
]),this.validpassword.bind(this)
]

自定义验证功能

validpassword(control: AbstractControl) {            
  const isEqual = Observable.of(this.password == control.value);
  return isEqual ? { valid : true } : null;         
}
这个错误说明了一切:

你在函数中返回对象| null.

只需将其更改为:

validpassword(control: AbstractControl) {
  return observabLeof('12345678910' === control.value).pipe(
    map(result => result ? { invalid: true } : null)
  );
}

STABKBLITZ DEMO

大佬总结

以上是大佬教程为你收集整理的angular – Async Validator Throw Expected validator返回Promise或Observable全部内容,希望文章能够帮你解决angular – Async Validator Throw Expected validator返回Promise或Observable所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。