为什么MatDialog没有显示?

时间:2019-02-25 12:18:25

标签: angular angular-material

这是我的登录组件:

 constructor(private router: Router, private dialog: MatDialog) { }
   login() : void {

      if(login_is_correct)
      {
        this.router.navigate(["home"]);
      }
      else
      {
          let dialogRef = this.dialog.open(IncorrectLoginInfoComponent, {
  data: { name: 'someName', title: 'Invalid credentials' },
});
      }
    });

  }

对话框IncorrectLoginInfoComponent

    export class IncorrectLoginInfoComponent implements OnInit {
  constructor(@Inject(MAT_DIALOG_DATA) public data: any, private dialogRef: MatDialogRef<IncorrectLoginInfoComponent>) { }

  closeDialog() {
    this.dialogRef.close('Dialog has been closed!');
  }

  ngOnInit() {
  }

模板:

    <h2 mat-dialog-title>{{ data.title }}</h2>
<mat-dialog-content>passed in by {{ data.name }} Are you sure?</mat-dialog-content>

<mat-dialog-actions>
  <button mat-button mat-dialog-close>Non</button>
  <!-- The mat-dialog-close directive optionally accepts a value as a result for the dialog. -->
  <button mat-button [mat-dialog-close]="true">Oui</button>
</mat-dialog-actions>

我还在app.module.ts的{​​{3}}中添加了以下内容:

     providers: [
  {provide: MAT_DIALOG_DEFAULT_OPTIONS, useValue: {hasBackdrop: false}}
  ],
   entryComponents: [
    IncorrectLoginInfoComponent
  ]

当我单击登录时,我看不到任何对话框,并且项目成功编译!!

此配置中缺少什么?

谢谢。

0 个答案:

没有答案