Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 角度材质:弹出窗口:在窗口打开并单击按钮时将数据发送给父对象_Angular_Typescript_Angular Material_Angular8_Material Dialog - Fatal编程技术网

Angular 角度材质:弹出窗口:在窗口打开并单击按钮时将数据发送给父对象

Angular 角度材质:弹出窗口:在窗口打开并单击按钮时将数据发送给父对象,angular,typescript,angular-material,angular8,material-dialog,Angular,Typescript,Angular Material,Angular8,Material Dialog,如何获取“角度材质”对话框的值并将其发送给父对象 我知道在他们关闭对话框后如何获取数据。 只是想知道当对话框仍然打开时,或者特别是当用户按下对话框中的按钮时,如何获取数据 public openPropertySearchDialog(): void { const propertySearchDialogRef = this.propertySearchDialog.open(PropertyGridDialogComponent, { width: '1500px',

如何获取“角度材质”对话框的值并将其发送给父对象

我知道在他们关闭对话框后如何获取数据。 只是想知道当对话框仍然打开时,或者特别是当用户按下对话框中的按钮时,如何获取数据

public openPropertySearchDialog(): void {
  const propertySearchDialogRef = this.propertySearchDialog.open(PropertyGridDialogComponent, 
  {
     width: '1500px',
     height: '950px',
     data: this.propertyList,
     hasBackdrop: false
   });
  
   propertySearchDialogRef.afterClosed().subscribe(result => {
     console.log('propertyResult', result);
   });
}
更新:

这将订阅数据。现在我只需要知道对话框组件中按下按钮时的数据。考虑为button press事件添加另一个订阅,寻找干净的方式,而不是添加两个订阅

propertySearchDialogRef .componentInstance.propertyOutput.subscribe((data: any) => {
  console.log('test',data);
});

当窗口关闭时,许多资源处于联机状态,查找“打开”并按下按钮(不关闭对话框)


在弹出组件上,可以使用输出事件发射器

  onAdd = new EventEmitter();
  constructor() {
    
  }
  
  onButtonClicked() {
    this.onAdd.emit('test');
  }
在父组件内部

  openDialog() {
      const ref = this._dialog.open(InnerComponent);
      const sub = ref.componentInstance.onAdd.subscribe((data) => {
        console.log(data);
      });
      dialogRef.afterClosed().subscribe(() => {
        sub.unsubscribe();
      });
  }
在这里,您正在订阅onAdd事件


仅当在按钮上单击按钮时,才会发出事件
(单击)
事件,调用
onButtonClicked()

我认为对话框中没有用于此的api。您只需使用一个服务来进行此通信。hi@Mohit,刚刚在问题注释中添加,现在我需要将输出事件与按钮click关联。只有在单击按钮时才会发出事件,在您的按钮(单击)上,调用按钮click()hi,您知道此问题的答案吗?谢谢结帐。