I have a component that pefectly works by itself, but doesn't work as dialog.
When I use DI to inject dialogRef and MAT_DIALOG_DATA
constructor(
public dialogRef: MatDialogRef<ChannelsComponent>,
@Inject(MAT_DIALOG_DATA) private data: any
) { }
it works as dialog only, but stops working by itself. When I try to render this component without dialog, I get:
StaticInjectorError(AppModule)
So, it works, but only in one role - either as a component by itself, or as a dialog, but not simultaneously.
The question is: can we use the same Angular component as dialog and by itself (without dialog) at the same time?
UPDATE:
Simplified versions:
https://stackblitz.com/edit/angular-kg32ui - works only as dialog, doesn't work if click on menu 'Channels'
https://stackblitz.com/edit/angular-sr9b8h - works as component and dialog, but doesn't provide data to the dialog
The only difference in 'channels.component.ts' that 1st version has these services injected to the constructor:
constructor(
public dialogRef: MatDialogRef<ChannelsComponent>,
@Inject(MAT_DIALOG_DATA) private data: any
) { }