Reputation: 11000
From Angular docs:
const form = new FormGroup({
password: new FormControl('', Validators.minLength(2)),
passwordConfirm: new FormControl('', Validators.minLength(2)),
}, passwordMatchValidator);
function passwordMatchValidator(g: FormGroup) {
return g.get('password').value === g.get('passwordConfirm').value
? null : {'mismatch': true};
}
I don't know how to call that passwordMatchValidator
function. Tried something like:
<div *ngIf="form.passwordMatchValidator">
But without any success...
Upvotes: 1
Views: 782
Reputation: 73357
To show the div with the error message if passwords don't match, you just do:
<div *ngIf="form.hasError('mismatch')">
Upvotes: 2