Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

304
Views
Argumento de tipo '{ validador: cualquiera; }' no es asignable al parámetro de tipo 'ValidatorFn

Tengo un problema al intentar crear un validador personalizado con Angular. De hecho, para mi página de registro, creé un formulario y para verificar si la contraseña y confirmar la contraseña coincidían, quería crear un validador personalizado.

Pero enfrenté el siguiente problema (ver imagen), e incluso todas las solicitudes similares que descubrí en Internet, no solucionaron mi problema.

El problema es: ingrese la descripción de la imagen aquí

 import { FormControl, FormGroup, Validators } from '@angular/forms'; import { USER_ATTRIBUTS } from 'src/app/globalVariable'; import { CustomValidators } from 'src/app/validators/custom-validators' export class UserFormSignUp extends FormGroup{ constructor(){ super({firstName: new FormControl('',[ Validators.required]), lastName: new FormControl('',[ Validators.required]), birthdate: new FormControl('', Validators.required), displayName: new FormControl('',[ Validators.required,]), email: new FormControl('',[ Validators.required, Validators.email]), password: new FormControl('',[ Validators.required]), confirmationPassword: new FormControl('',[ Validators.required])}, { validator: CustomValidators.passwordMatchValidator }); } get firstName() : FormControl{ return this.get('firstName') as FormControl; } get lastName() : FormControl{ return this.get('lastName') as FormControl; } get birthdate() : FormControl{ return this.get('birthdate') as FormControl; } get displayName() : FormControl{ return this.get('displayName') as FormControl; } get email() : FormControl{ return this.get('email') as FormControl; } get password() : FormControl{ return this.get('password') as FormControl; } get confirmationPassword() : FormControl{ return this.get('confirmationPassword') as FormControl; }

}

Y custom-validators.ts:

 import { ValidationErrors, ValidatorFn, AbstractControl } from '@angular/forms'; checkPasswords: ValidatorFn = (group: AbstractControl): ValidationErrors | null => { let pass = group.get('password')?.value; let confirmPass = group.get('confirmPassword')?.value return pass === confirmPass ? null : { notSame: true } }

}

Si tienes alguna idea... te lo agradecería.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Al extender FormGroup y llamar a super con { validator: CustomValidators.passwordMatchValidator } , no cumple con la firma real del constructor de FormGroup que se supone que debe tomar un ValidatorFn simple como segundo parámetro, no incrustado en un objeto como lo hizo usted.

Prueba así:

 export class UserFormSignUp extends FormGroup { constructor() { super( { firstName: new FormControl("", [Validators.required]), lastName: new FormControl("", [Validators.required]), birthdate: new FormControl("", Validators.required), displayName: new FormControl("", [Validators.required]), email: new FormControl("", [Validators.required, Validators.email]), password: new FormControl("", [Validators.required]), confirmationPassword: new FormControl("", [Validators.required]), }, CustomValidators.passwordMatchValidator ); } }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!