Angular NullInjectorError: No Provider for MatDialog

In my situation, I was seeing this error while trying to build a dialog component like:

my-dialog.component.ts

<mat-dialog-container>
  <mat-dialog-content>
    <p>Hello</p>
    <p>I am a dialog</p>
  </mat-dialog-content>
  <mat-dialog-actions>
    <button mat-raised-button>Click me</button>
  </mat-dialog-actions>
</mat-dialog-container>

The problem was that I was using mat-dialog-container. This is not required for components that you'll be rendering via matDialog.open(MyDialogComponent)

Instead, just remove mat-dialog-container entirely and just use the child nodes.


Please note that in Angular Material you have to import all elements module into your module.ts. You have to import and add module in your module.ts like this

import {MatDialogModule} from '@angular/material/dialog';


import : [MatDialogModule]

For reference see the example from official documentation here