0

So when i trigger an event emitter from the dialog: ...

onAdd = new EventEmitter();

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

And I listen to this from the parent:

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

How can I send "results" back to the same dialog?

Edit: I also need to trigger a function call in the dialog when "results" is ready.

1 Answers1

2

You can pass value back to your dialog this way:

 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
  })
});

Because dialogRef.componentInstance gives you the full instance class of the dialog, you can do what you do from the dialog class itself.

dabishan
  • 671
  • 3
  • 10