extensions
extensions copied to clipboard
Problem with reactive mtx-select inside an ng-template mat-dialog
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?
The error is clear. You should use formControlName
instead of ngModel
https://angular.io/api/forms/FormControlName#register-formcontrol-within-a-group
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.
Can you provide an online demo?
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.
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.
Is there any news?
I have submitted the issue to material. https://github.com/angular/components/issues/25515
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...
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.