0

因此,当我从对话框触发事件发射器时:...

onAdd = new EventEmitter();

onButtonClick() {
  this.onAdd.emit();
}

我从家长那里听到这个:

let dialogRef = this.dialog.open(Component);
const sub = dialogRef.componentInstance.onAdd.subscribe(() => {
  myservice.subscribe(results => /*send back to dialog*/)
});

如何将“结果”发送回同一个对话框?

编辑:当“结果”准备好时,我还需要在对话框中触发函数调用。

4

1 回答 1

1

您可以通过这种方式将值传递回对话框:

 const sub = dialogRef.componentInstance.onAdd.subscribe(() => {
  myservice.subscribe(results => {
    // passes results to your dialog. you need to create a property 'results' in you dialog class though.
    dialogRef.componentInstance.results = results; 
    dialogRef.componentInstance.someFunction(); // function you want to trigger after results is ready
  })
});

因为dialogRef.componentInstance为您提供了对话框的完整实例类,所以您可以从对话框类本身执行您所做的事情。

于 2020-06-10T01:23:49.593 回答