воскресенье, 12 ноября 2017 г.

No provider for MatDialogRef across different modules

This post will be about Dialog of Angular Material.

If you want to use dialog across different modules (for example, you call module login) you will see follow error:
Error: No provider for MatDialogRef
or the same if you want to get data form parent module:
Error: No provider for MAT_DIALOG_DATA
because this class is not @Injectable, and works only through MatDialog. Maybe there has some bug, connecte to InjectionToken...

So, you need insert MatDialog to your constructor of called component of other module:
constructor(public dialog: MatDialog) {}
Then you can find your dialog by:
const ref:MatDialogRef<any> = this.dialog.openDialogs[0];


Good luck!


PS: maybe I missed something and MatDialogRef works fine with different the modules for somebody, please, tell me, I will be appreciated.