When utilizing a component via routing as well as injecting it as the "target" of a modal dialog, I encountered an issue:
export class Component1 implements OnInit {
constructor(private service: <someService>,
public dialogRef: MatDialogRef<Component1>, //These 2 lines are used as
//injection from the opener
@Inject(MAT_DIALOG_DATA) public data: any) {}
Here is the code of the "opener":
openComponent1aSModalPage()
{
Const dialogRef = this.dialog.open(Component1, {
width: '70%',
height: '70%',
data: {property: propertyValue}
});
While it works when I trigger the opener, attempting to access the same component via regular routing results in:
Error: Uncaught (in promise): NullInjectorError: StaticInjectorError(AppModule)[Component1 -> MatDialogRef]: StaticInjectorError(Platform: core)[Component1-> MatDialogRef]: NullInjectorError: No provider for MatDialogRef!
How can I modify the component to function in both scenarios?