Ricky Cuarez
Ricky Cuarez

Reputation: 768

StaticInjectorError(AppModule)[MainComponent -> MatDialog]

When using Materials Dialog, I can't remove the error mentioned in the subject. I had already imported the MatDialogModule and added the entryComponents. I simply want to open my edit-api component when the editAPI button is clicked inside my main component. What am I doing wrong?

Here is the link: https://stackblitz.com/edit/exercise-basic-c

Upvotes: 0

Views: 847

Answers (2)

user9966539
user9966539

Reputation:

Try following in your edit api component

import { Component, Inject, OnInit } from '@angular/core';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material';

@Component({
  selector: 'app-alert-dialog',
  templateUrl: './alert-dialog.component.html',
  styleUrls: []
})
export class AlertDialogComponent implements OnInit {
  constructor(
    public dialogRef: MatDialogRef<your_component>,
    @Inject(MAT_DIALOG_DATA) public data) { }

  closeDialog(): void {
    this.dialogRef.close();
  }

  ngOnInit() {
  }
}

You need to use @Inject MAT_DIALOG_DATA in your dialog component.

Upvotes: 0

Kinjal
Kinjal

Reputation: 680

you have to change following

import { MatDialog, MatDialogConfig } from '@angular/material';

by

import { MatDialog, MatDialogConfig } from '@angular/material/dialog';

to resolve your error.

Upvotes: 1

Related Questions