title: Angular open a dialog and return observable for action result
body: <p>I would like to show a dialog by code (not MatDialog but a custom one) and then return an Observable that will trigger a result to the caller.</p>
  <p>Something like this:</p>
  <pre><code>    @ViewChild(PopupComponent)
        myDialog: PopupComponent;
  
  
  public show(){
     this.myDialog.show().subscribe(v =&gt; {
         if(v.OkClicked){
            console.log('ok clicked!');
         }
     });
  }
  
  
  export interface DialogResult{
      OkClicked: boolean;
  }
  
  @Component({
    selector: 'f-popup',
    outputs: [ &quot;onClose&quot; ],
    templateUrl: './popup.component.html',
    styleUrls: ['./popup.component.css']
  })
  
  private _result : ReplaySubject&lt;DialogResult&gt;;
  private _obsResult: Observable&lt;DialogResult&gt;;
  
  public show(): Observable&lt;DialogResult&gt;(){
      // show the dialog
      if(!this._result){
          this._result = new ReplaySubject&lt;DialogResult&gt;(1);
      }
      return this._obsResult.asObservable();
  }
  
  public onOkClick(){
     let result: DialogResult = {OkClicked: true};
     this._obsResult.next(result);
  }
  
  public onClosed(){
      this._obsResult.complete();
      this._obsResult = null;
  }
  
  ngOnDestroy() {
      if(this._obsResult) {
        this._obsResult.complete();
        this._obsResult = null;
     }
  }
  </code></pre>
  <p>The dialog is not destroyed when it is closed, it is a component inside anohther component that is shown and hidden.
  My question is, is it a good way to recreate a Subject on every show of the dialog? Are there memory leaks for this way?</p>