Step by Step Creating Password Match Validator in Angular | Cross Controls Validations in Angular

Step by Step Creating Password Match Validator in Angular | Cross Controls Validations in Angular

NomadCoder

1 год назад

7,023 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

Coders Expo
Coders Expo - 06.10.2023 00:07

Thanks for this! Just a note to build on your effort here. If you want to pass parameters to your custom validator function you can do it like so:

import { AbstractControl, ControlContainer, ValidationErrors, ValidatorFn } from "@angular/forms";

export function checkvaluesmatch(val1: any, val2: any): ValidatorFn {
return (control: AbstractControl): ValidationErrors | null => {

let v1 = control.get(val1);
let v2 = control.get(val2);

if (v1 && v2 && v1?.value != v2?.value) {
return {
valuematcherror: true
}
}

return null;
}
}

This way you are not tied to using the key words 'password' and 'confirmpassword'. This is a more abstract approach. Then just call it like..
....{ validators: checkvaluesmatch('password', 'confirmpassword') });

Ответить
edwedw123
edwedw123 - 04.08.2023 00:49

thanks for the video but mat-error doesnt work with this validations

Ответить
Ayzat Latipov
Ayzat Latipov - 17.07.2023 15:10

That's great! Thank you so much for the tutorial. Short and beautiful!

Ответить
Brinda Messu
Brinda Messu - 14.07.2023 19:59

thank you very much

Ответить
Мария Божко
Мария Божко - 05.06.2023 14:19

Thank you very much! you've been incredibly helpful to me!

Ответить
Rafaela Rolim
Rafaela Rolim - 17.05.2023 11:54

Awesome, thanks!

Ответить
Vu Minh
Vu Minh - 16.02.2023 10:12

niceeee thanks so much

Ответить
M M
M M - 30.01.2023 10:57

Hi @dhanjay kumar, recently wateched your very nice, my one suggestion is, am a begginer to start angular , can you re- arrange the begginer level & intermediate level in your playlist, and also you created batch 4 in playlist it's okay with start that beginner level

Ответить
Jayshankar Behera
Jayshankar Behera - 30.01.2023 08:35

Nice

Ответить