Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
343 views
in Technique[技术] by (71.8m points)

Error occurring in Angular Material Dialog Popup

I have been trying to put Modal popup in my site using Angular Material Dialog, 1st time it all came perfect But it started to show error after..

I have imported the MatDialogModule in moduleTs import { MatDialogModule } from '@angular/material/dialog'; also declared in imports

In ComponentTs:

constructor(public dialog: MatDialogModule) {};
  ngOnInit() {
  }
  openDialog(){
    this.dialog.open(DialogStudyModeComponent);
  }

the error shown was : Property 'open' does not exist on type 'MatDialogModule'.

45 this.dialog.open(DialogStudyModeComponent);

question from:https://stackoverflow.com/questions/66062284/error-occurring-in-angular-material-dialog-popup

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

you importing the wrong dialog.

MatDialogModule is to be put in your module.

MatDialog is for your component.

So:

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

  constructor(public dialog: MatDialog) {}
  openDialog() {
      this.dialog.open(DialogStudyModeComponent);
  }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...