Javascript RXJS和Angular-我应该使用ReplaySubject和Observable吗?

Javascript RXJS和Angular-我应该使用ReplaySubject和Observable吗?,javascript,angular,rxjs,Javascript,Angular,Rxjs,我构建了一个模式对话框,允许开发人员在主体中指定自己的内容。底部有两个按钮-是或取消 实现自己模式的开发人员可以选择订阅/不订阅“是”或“取消”按钮 我可以从很多选项中选择,从模式返回到已单击“是”或“取消”的页面。我可以使用行为主体,回放主体,可观察,事件发射器 我希望模式在单击Yes或Cancel时自动关闭,并继续告诉调用页面发生了什么 我添加了一个.do(),以便在通知订阅者之前关闭模式。我还在ngAfterViewInit()中添加了一个默认订阅,以防没有人处理取消事件 问题:我应该以这

我构建了一个模式对话框,允许开发人员在主体中指定自己的内容。底部有两个按钮-取消

实现自己模式的开发人员可以选择订阅/不订阅“是”或“取消”按钮

我可以从很多选项中选择,从模式返回到已单击“是”或“取消”的页面。我可以使用行为主体回放主体可观察事件发射器

我希望模式在单击Yes或Cancel时自动关闭,并继续告诉调用页面发生了什么

我添加了一个.do(),以便在通知订阅者之前关闭模式。我还在ngAfterViewInit()中添加了一个默认订阅,以防没有人处理取消事件

问题:我应该以这种方式被重放主体和观察,还是有更好的方法来处理这个问题?

modal.ts

@Component({
  selector: 'app-modal',
  templateUrl: './modal.component.html',
  styleUrls: ['./modal.component.css']
})
export class ModalComponent implements OnInit, AfterViewInit {
  // Outputs
  @Output() onYesClicked: Observable<void>;
  @Output() onNoClicked: Observable<void>;
  @Output() onCancelClicked: Observable<void>;

  private yesReplaySubject: ReplaySubject<void> = new ReplaySubject<void>();
  private noReplaySubject: ReplaySubject<void> = new ReplaySubject<void>();
  private cancelReplaySubject: ReplaySubject<void> = new ReplaySubject<void>();

  constructor() {
    this.configuration = new DefaultModalConfigurationBuilder().build();
    // Do a follow up action of hiding the modal when a replay subject is triggered
    this.onYesClicked =     this.yesReplaySubject.do(x => this.hide());
    this.onNoClicked =      this.noReplaySubject.do(x => this.hide());
    this.onCancelClicked =  this.cancelReplaySubject.do(x => this.hide());
  }

 public ngAfterViewInit() {
    // Some subscription set up incase no one handles the cancel click etc...
    this.onYesClicked.subscribe();
    this.onNoClicked.subscribe();
    this.onCancelClicked.subscribe();
  }

  private yesClicked = (): void => this.yesReplaySubject.next(null);
  private noClicked = (): void => this.noReplaySubject.next(null);
  private cancelClicked = (): void => this.cancelReplaySubject.next(null);
}
...
private onYesClicked(): void {
// Do something here
}
...
<app-modal title="Modal Demo (onYesClicked)="handleYesClicked()">
  <form novalidate>
    <p>My modal content</p>
  </form>
</app-modal>
...
private onYesClicked(): void {
// Do something here
}
...