when try to add confirm mail function group get error Expected 1-2 arguments but got 3. ts(2554)?

huangapple go评论83阅读模式
英文:

when try to add confirm mail function group get error Expected 1-2 arguments but got 3. ts(2554)?

问题

问题

在将确认电子邮件作为第三个参数添加时,出现错误"Expected 1-2 arguments but got 3. ts(2554)"?

我在使用 Angular 7 开发时创建了用户注册表单。

当进行验证时,将用户邮件与确认邮件进行比较时,Reactive 表单中的函数组不接受将邮件确认作为参数添加,如下所示的代码。

那么如何在注册表单中添加确认电子邮件?

import { MustMatchEmail } from '../helpers/EmailValidator';
import { MustMatch } from '../helpers/must-match.validator';
constructor() {}
UserMail = new FormControl('', [Validators.required, Validators.email, Validators.pattern('^[a-z0-9._%+-]+@[a-z0-9.-]+\\.[a-z]{2,4}$'), Validators.maxLength(100)]);

ConfirmedEmail = new FormControl('', [Validators.required, Validators.email, Validators.maxLength(100)])

ngOnInit() {
  this.createFormValidations();
}
createFormValidations() {
  this.registerForm = this.formBuilder.group({
      UserMail: this.UserMail,
      ConfirmedEmail: this.ConfirmedEmail,
      UserPass: this.UserPass,
      ConfirmedPassword: this.ConfirmedPassword,

    }, {
      validator: MustMatch('UserPass', 'ConfirmedPassword')
    },
    // 这里出现错误,函数不接受邮件确认
    {
      validator: MustMatchEmail('UserMail', 'ConfirmedEmail')
    }
  );
}

when try to add confirm mail function group get error Expected 1-2 arguments but got 3. ts(2554)?

英文:

Problem

error Expected 1-2 arguments but got 3. ts(2554) when add confirm email as third argument ?

I work on angular 7 I make register users form

when do validation compare user mail to confirm mail on Reactive form .

function group not accept to add argument for mail confirm as code below

so How to add confirm email on register form ?

import {MustMatchEmail} from '../helpers/EmailValidator';
import {MustMatch} from '../helpers/must-match.validator';
constructor() {}
UserMail = new FormControl('', [Validators.required, Validators.email, Validators.pattern('^[a-z0-9._%+-]+@[a-z0-9.-]+\\.[a-z]{2,4}$'), Validators.maxLength(100)]);

ConfirmedEmail = new FormControl('', [Validators.required, Validators.email, Validators.maxLength(100)])

ngOnInit() {
  this.createFormValidations();
}
createFormValidations() {
  this.registerForm = this.formBuilder.group({
      UserMail: this.UserMail,
      ConfirmedEmail: this.ConfirmedEmail,
      UserPass: this.UserPass,
      ConfirmedPassword: this.ConfirmedPassword,

    }, {
      validator: MustMatch('UserPass', 'ConfirmedPassword')
    },
    //here error function not accept mail confirm
    {
      validator: MustMatchEmail('UserMail', 'ConfirmedEmail')
    }
  );
}

when try to add confirm mail function group get error Expected 1-2 arguments but got 3. ts(2554)?

答案1

得分: 1

Reference: https://alligator.io/angular/reactive-forms-custom-validator/

this.registerForm = this.formBuilder.group({
      userMail: [this.userMail, MustMatchEmail('UserMail', 'ConfirmedMail')],
});
英文:

Try this: Reference: https://alligator.io/angular/reactive-forms-custom-validator/

this.registerForm = this.formBuilder.group({
userMail: [this.userMail, MustMatchEmail('UserMail','ConfirmedMail')],
});
</details>

huangapple
  • 本文由 发表于 2020年1月4日 00:20:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/59581883.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定