Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow mat-error in mat-form-field subviews #15778

Open
alirezamirian opened this issue Apr 10, 2019 · 0 comments
Open

Allow mat-error in mat-form-field subviews #15778

alirezamirian opened this issue Apr 10, 2019 · 0 comments
Labels
area: material/form-field P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent

Comments

@alirezamirian
Copy link

What is the expected behavior?

NOTE: it's more of an improvement (but a really critical one) than a bug.

mat-error should work even if it's not used as direct child of mat-form-field. It should work if it's used inside a component which itself is used in mat-form-field.

This is particularly necessary for handling error messages in a reusable component.
A real-world application may have several forms with a lot of validators on their fields.
Repeating a bunch of mat-errors and corresponding error messages for each usecase is just tedious.

Suggested solution

I think the reason this currently doesn't work is because @ContentChildren decorator is used to get a hold of mat-error instances. However @ContentChildren doesn't work for nested components and aparently this is by design.
Instead of using @ContentChildren , MatError can inject MatFormField and register itself into it.

What is the current behavior?

mat-error only works if it's directly used inside mat-form-field. If it's used inside a nested component, it doesn't work as expected.

What are the steps to reproduce?

https://stackblitz.com/angular/kllvoljyoem

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

@angular/cdk@7.3.0
@angular/material@7.3.0
Angular: 7.2.3

Is there anything else we should know?

@alirezamirian alirezamirian changed the title Allow nested mat-errors in mat-form-field Allow mat-error in mat-form-field subviews Apr 10, 2019
@andrewseguin andrewseguin added the P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent label Apr 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: material/form-field P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent
Projects
None yet
Development

No branches or pull requests

2 participants