1

Before this component was being loaded into MatDialog but now the requirement is to load it on some url i.e. http://localhost:4200/some-url and when I load this component via url and getting error

NullInjectorError: No provider for x!

Here is the component that I am trying to load on url.

export class MyComponent {
  
  constructor(
    public dialogRef: MatDialogRef<MyComponent>,
    private fb: FormBuilder,
    @Optional() @Inject(MAT_DIALOG_DATA) public data: any
  ) { }

}

enter image description here

WasiF
  • 26,101
  • 16
  • 120
  • 128

2 Answers2

2

I had component that had MatDialog related objects that were responsible for receiving data i.e. @Optional() @Inject(MAT_DIALOG_DATA) public data: any, something like this:

export class MyComponent {
  
  constructor(@Optional() @Inject(MAT_DIALOG_DATA) public data: any) { }

}

Later on, with the requirement change, I had to load this component on some url instead of loading on a dialog. Just removed the dialog related data and it is done.

export class MyComponent {
  
  constructor() { }

}
WasiF
  • 26,101
  • 16
  • 120
  • 128
1

Include MatDialogModule in imports array in the module in which this component is registered.

Suraj Kumar
  • 281
  • 6
  • 13