ng-matero / extensions

Angular Material Extensions Library.
https://ng-matero.github.io/extensions/
MIT License
393 stars 48 forks source link

Problem with reactive mtx-select inside an ng-template mat-dialog #119

Closed andreanaFelicione closed 1 year ago

andreanaFelicione commented 1 year ago

I have a component mtx-select inside an ng-template that contains a mat-dialog, and when I open the dialog I have in console the error message:

ERROR Error: NG01350: ngModel cannot be used to register form controls with a parent formGroup directive. Try using formGroup's partner directive "formControlName" instead.

My mtx-select is in a reactive form, so there is no attribute "ngModel" in my form.

How can I resolve this issue?

nzbin commented 1 year ago

The error is clear. You should use formControlName instead of ngModel https://angular.io/api/forms/FormControlName#register-formcontrol-within-a-group

andreanaFelicione commented 1 year ago

As I said, I already use formControlName and the term ngModel does not appear anywhere in my code.

I take this opportunity to reiterate that the problem occurs only when the form is contained within a mat-dialog opened via ng-template with dialog.open(myTemplateReference); if the same form is inserted in an open mat-dialog using a component with dialog.open(myDialogComponent); the problem does not arise.

nzbin commented 1 year ago

Can you provide an online demo?

andreanaFelicione commented 1 year ago

Sorry for the late reply, but I was on vacation. I created a sample demo here where the error is visible in Test3. There is a bug on the display of dialogs that I could not solve in the example, please do not pay attention to it.

nzbin commented 1 year ago

Thanks for your demo, I tested this issue and I found it has no problem in v12 and v13. I'm not sure if this is a bug of material in v14. I will test it again and try to fix it.

andreanaFelicione commented 1 year ago

Is there any news?

nzbin commented 1 year ago

I have submitted the issue to material. https://github.com/angular/components/issues/25515

andreanaFelicione commented 1 year ago

Ok thanks. In the meantime so i could go back to version 13 of material to avoid the error occurring? Can you confirm that the error does not occur with 13? In my project I have many points where I use ngTemplate and I need a solution in a short time. I don't know how long it will take material developers to fix the bug...

nzbin commented 1 year ago

I have fixed this issue by myself, but I‘m not sure if there has some other side effects. You can try the new version 14.4.1.