如何正确配置MatDialog?

时间:2019-02-23 12:34:59

标签: angular

当用户输入错误的用户名和密码组合时,尝试在Angular页面中显示MatDialog,而是显示了自己的登录页面。 参见下图: Dialog

这是我对LoginComponent感到厌倦的内容:

     login() : void {
              const dialogConfig = new MatDialogConfig();
  this.utilisateurService.getLogin(this.username,this.password).subscribe((util: UtilisateurModel) => {
              this.utilisateur = util;
              if(util)
              {
                this.router.navigate(["home"]);
              }
              else
              {
                dialogConfig.disableClose = true;
                dialogConfig.autoFocus = true;
                dialogConfig.data = {
                  id: 1,
                  title: 'Désolé, nom d\'utilisateur ou mot de passe non reconnu.'
              };
          this.dialog.open(LoginComponent, dialogConfig);
              }
            });

          }

我尝试通过在entryComponents的{​​{1}}中添加@NgModulethis answer,但未做任何更改:

app.module.ts

提前谢谢

1 个答案:

答案 0 :(得分:0)

在这一行:

this.dialog.open(LoginComponent, dialogConfig);

您应该传递另一个组件,该组件说明凭证有误而不是LoginComponent。因此,您需要专门定义新组件以显示该错误消息,将其传递到open(),并且不要忘记在entryComponents中注册它。 希望有帮助。

相关问题