尝试创建密码确认验证器时出错期望的验证器返回Promise或Observable

问题描述

我不知道为什么会出现此错误。每次输入时,都会显示以下错误:

错误:预期的验证程序返回Promise或Observable。

我正在尝试工作的代码:

验证器

export function passwordMatchValidator(passwordKey: string,passwordConfirmationKey: string,group: FormGroup): any {

    if (group) {
        if (group.get(passwordKey).value !== group.get(passwordConfirmationKey).value) {
            return { 'passwordMismatch': true };
        }
    }

    return null
}

FormGroup 代码:

this.formGroup.setValidators(passwordMatchValidator("password","confirmPassword",this.formGroup));
this.formGroup.updateValueAndValidity();

HTML

<mat-error *ngIf="formGroup.controls['confirmPassword'].errors?.passwordMismatch"></mat-error>

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)