No provider for MatDialogRef!
constructor(public dialog: DialogRef
Gives error 'No provider for MatDialogRef!'
Have you added it to your module as a provider? Next to that: Please keep GitHub issues for bug reports / feature requests. Better avenues for troubleshooting / questions are stack overflow, gitter, mailing list, etc.
I tried to add MatDialogRef in providers array of module, but it gives an error 'can't resolve all parameters for MatdialogRef'
Please keep GitHub issues for bug reports / feature requests. Better avenues for troubleshooting / questions are stack overflow, gitter, mailing list, etc.
@darshu514 are you find any solution of this issue No provider for MatDialogRef
Do you have a solution for this problem?
No, I think it’s an open issue. I found a work around by using https://github.com/shlomiassaf/ngx-modialog
The implementation is pretty simple
got it, in my case there is two component one is DialogComponent and another is AddComponent from we open the dialog e.g , and i accidentally init DialogComponent without any provider like AddComponent, if i init DialogComponent from AddComponent like, this.dialog.open(DialogComponent',{}) , then it not give any error.
Same here, still no solution?
@mkamrani create a question on stackoverflow, we all try to help
Hey, Please try import MatDialog from @angular/material and provide it into providers array inside appModule.
Its worked for me.
@unknown4unnamed +1
You will get that exact "No provider for MatDialogRef" error in case you include your dialog's component html selector in any html file.
<dialog-html-selector></dialog-html-selector>
There is no need for that, do not include the html selector of the dialog component anywhere. You will get the error otherwise
Is it possible to have a component that opens in a dialog on some occasions and also renders using the html selector on other occasions? I am trying to make a feature of my application responsive and when the display is small I want a dialog otherwise I want to render it with the html selector.
The thing is that your component is made for being loaded in a MatDialog because in your *.ts file you are surely getting in your constructor a MatDialogRef:
A dialog is opened by calling the open method with a component to be loaded and an optional config object. The open method will return an instance of MatDialogRef:
let dialogRef = dialog.open(UserProfileComponent, {
height: '400px',
width: '600px',
});
The MatDialogRef provides a handle on the opened dialog. It can be used to close the dialog and to receive notification when the dialog has been closed.
dialogRef.afterClosed().subscribe(result => {
console.log(`Dialog result: ${result}`); // Pizza!
});
dialogRef.close('Pizza!');
Maybe you can have a more general component specific for loading dialogs with the structure of a dialog in the dom with "mat-dialog-title", "mat-dialog-content", "mat-dialog-actions"... Receiving in the data (MAT_DIALOG_DATA) the parameters of title and actions and then within the content section of the dialog you can load the component you want to use also in the DOM with the selector??
I am not an angular expert but it is the best idea I can think of now.
I removed the dialog component selector and it worked fine! :) It was like this:
@Component({
selector: 'app-users-dialog',
templateUrl: './users-dialog.component.html',
styleUrls: ['./users-dialog.component.css']
})
And I changed to:
@Component({
templateUrl: './users-dialog.component.html',
styleUrls: ['./users-dialog.component.css']
})
@marylly Thank you, same here. It's kind of logic if you think about there is no selector for the modal content, but I haven't found any documentation about it. Thanks again!
Can anyone please Help me with this?
compiler.js?dd9e:485 Uncaught Error: Unexpected value 'MatDialogRef' imported by the module 'AppModule'. Please add a @NgModule annotation.
@Ukmandal could you please provide your app.module.ts? Or the correspondant module of the view your are trying to load the modal in? I think you are declaring MatDialogRef on it or something like that instead of the MatDialogModule
I'm having the same issue. I have a form component which sometimes I need to display in a modal dialog and sometimes as an independent page (by navigation). It works fine in the modal but when I try to navigate to that page, I get this error "NullInjectorError: No provider for MatDialogRef!"
For me, none of these solutions worked. However, what did work for me was stubbing out the MatDialogRef. You solve you problem like this:
Below your imports:
const matDialogRefStub = {};
Add this to the providers section of your testbed config:
{provider: MatDialogRef, useValue: matDialogRefStub}
Also, don't forget to have MatDialog as a provider as well.
That should be it, goodluck!