小编0x4*_*E79的帖子

角度材质对话框立即关闭

我尝试从我的组件中打开“角度材质”对话框。但对话框打开后立即关闭。

我知道 Stackoverflow 上有一些类似的问题,但他们的答案似乎对我不起作用。不确定从订阅的完整部分中调用对话框函数是否是问题所在。

示例DialogComponent.ts

export class ExampleDialogComponent implements OnInit {

  inputVal1: string;
  inputVal2: string;

  constructor(public dialogRef: MatDialogRef<ExampleDialogComponent>,
              @Inject(MAT_DIALOG_DATA) public data: any, private formBuilder: FormBuilder) {
    this.inputVal1 = data.inputVal1;
    this.inputVal2 = data.inputVal2;
  }

  ngOnInit() {
    this.firstFormGroup = this.formBuilder.group({
      firstCtrl: ['', Validators.required]
    });
    this.secondFormGroup = this.formBuilder.group({
      secondCtrl: ['', Validators.required]
    });
  }

  onCloseConfirm() {
    setTimeout(() => {
      this.dialogRef.close({
      message: 'Confirm',
      outputVal1: this.inputVal1,
      outputVal2: this.inputVal2,
      });
    }, 0);
  }
}
Run Code Online (Sandbox Code Playgroud)

示例DialogComponent.html

<mat-step>
      <ng-template matStepLabel>last step</ng-template>
      <mat-dialog-actions>
        <button mat-button [mat-dialog-close]="onCloseConfirm()">add</button>
        <button mat-button mat-dialog-close>close</button>
      </mat-dialog-actions> …
Run Code Online (Sandbox Code Playgroud)

typescript angular-material angular

2
推荐指数
2
解决办法
7271
查看次数

标签 统计

angular ×1

angular-material ×1

typescript ×1