Angular 6 - Expected validator to return Promise or Observable in async validator

混江龙づ霸主 提交于 2019-12-06 09:30:43

RxJS's map don't take a second function argument.
I guess you want something like this:

if (new RegExp(validationUtils.emailRegex).test(email)) {
  return this.userService
  .checkIfEmailExist(email)
  .pipe(
    map(data => {emailExist: true}),
    catchError(error => null)
  );
}

return of(null);

You have to return the observable from checkIfEmailExist:

// ...
return this.userService
  .checkIfEmailExist(email)
  .pipe(
// ...

When you add multiple validators, then you need to add your validators inside another third bracket '[]' . Like Below:

this.yourForm= this.formBuilder.group({
    amount: [null, [Validators.required, Validators.min(1)]],
});
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!