Angular 6 和 Angular material 对话框在订阅方法中成功添加到数据库后未打开

Angular 6 and Angular material dialog box is not opening after successful add to database inside subscribe method

我正在尝试在成功插入数据库后打开 angular material 对话框组件:

addHousehold(){
    let last_name_ar = this.formGroup.controls['last_name_ar'].value;

    let last_name_en = this.formGroup.controls['last_name_en'].value;
    .......//Other data
    let arrayOfLegalProtection = this.arrayOfLegalProtection;

    this.showSpinner = true;
    this.auth.addHousehold(this.unit_id,
      ...//Other data
      this.user_id
      ).subscribe(
      (data)=>{
        console.log(data);
        if(data=="enableAdd")
        {
          this.showSpinner = false;
          this.enableDisableAdd = "enableAdd";
          this.formGroup.reset();
          this.arrayOfLegalProtection = [];
          // this.openDialog(data);
          this.openDialog();
        }
        else
        {
          this.showSpinner = true;
          this.enableDisableAdd = "disableAdd";
          this.formGroup.reset();
        }
      },
      (error)=>{
        console.log(error);
      }
    )
}

如您所见,我已将以下行添加到 subscribe() 方法的 (data) 部分:

this.openDialog();

openDialog() 具有以下代码:

openDialog(): void {
    const dialogRef = this.dialog.open(AddIndividualComponent, {
      width: '250px',
      data: {unit_id: this.unit_id}
    });

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

    });
}

成功插入数据库后,对话框不会打开,控制台也不会显示任何错误。

当我将 this.openDialog() 移动到订阅方法之外时,对话框正常打开。

我什至试图在 subscribe() 中从头开始声明该函数,但我收到一条错误消息,找不到 openDialog().

如何在添加到数据库后打开angular material的对话框并收到成功响应?

对话框未显示的唯一原因是以下条件不成立,因此 'openDialog()' 未被调用。请查收。

if(data=="enableAdd") //not true