No provider for MatDialogRef using angular material 19

Discussão em 'Angular' iniciado por Jeanluca Scaljeri, Dezembro 29, 2024.

  1. I'm using angular 19 and angular material 19. Now I'm doing as far as I know some basic dialog stuff

    I'm, lets say rendering FooComponent, which does the following

    openDialog(): void {
    const dialogRef = this.dialog.open<string>(BarComponent, {});

    dialogRef.closed.subscribe(result => {
    console.log('The dialog was closed');
    });
    }


    This works ok, the BarComponent is rendered as a dialog. However, now I want to close the dialog from inside BarComponent, so I injected MatDialogRef. As soon as I do that I get the following error

    NullInjectorError: No provider for MatDialogRef!


    BarComponent:

    @Component({
    imports: [CommonModule]
    ...
    })
    export class BarComponent {
    private dialogRef = inject(MatDialogRef)

    closeDialog() {
    this.dialogRef.close()
    }
    }


    I tried many things, such as import MatDialogModule in FooComponent and BarComponent, but none of them helped. Any suggestions what might be the issue here?

    Continue reading...

Compartilhe esta Página