angulartypescriptangular7angular-reactive-formsangular-resource

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')
    }
  );
}

cannot add confirm email on function group


Solution

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

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