Skip to content

mat-error can not be displayed when i compare password and confirmPassword #14118

Closed
@pierre03

Description

@pierre03

Bug, feature request, or proposal:

I tried to compare the value of two fields in the form, but it doesn't work with mat-error.
When i set a password, i want to display two error messages under the two input component or display at least the error message under the empty component.

Here is one of the input component, another one is coded with the same code.

HTML:

*****
<mat-error *ngIf="form.errors.mismatch">
mismatch error

TYPESCRIPT:

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

What is the expected behavior?

I want to display the error after the input

What is the current behavior?

No error displayed

What are the steps to reproduce?

Providing a StackBlitz reproduction is the best way to share your issue.

StackBlitz starter: https://goo.gl/wwnhMV

What is the use-case or motivation for changing an existing behavior?

I want to compare the password, and display the error message after each input component
It works when i use the <div *ngIf="hasError()"> to dislpay the error message, but not with mat-error.

Which versions of Angular, Material, OS, TypeScript, browsers are affected?

Angular V5.0.3
Material: V5.0.0-rc.1

Is there anything else we should know?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions