相关疑难解决方法(0)

Subject和BehaviorSubject有什么区别?

我不清楚Subject和BehaviorSubject之间的区别.是否只是BehaviorSubject具有getValue函数?

rxjs

191
推荐指数
6
解决办法
7万
查看次数

Angular中的Subject vs BehaviorSubject vs ReplaySubject

我一直在寻找那些3:

主题,行为主体重播主题.我想使用它们,知道何时以及为什么,使用它们有什么好处,虽然我已阅读文档,观看教程和搜索谷歌,但我没有对此有任何意义.

那他们的目的是什么?一个真实的案例将是非常感谢它甚至不必编码.

我更喜欢一个干净的解释,而不只是"a + b => c,你订阅了......"

谢谢

javascript reactive-programming rxjs angular2-observables angular

89
推荐指数
6
解决办法
3万
查看次数

订阅一个主题在init上第一次不起作用

我有一项服务从服务器获取一些数据并更新一些主题,在我的组件的 ngOnInit 函数中我正在订阅该主题。我已确认主题已正确更新。

以下是我的服务功能,它从服务器获取数据并更新主题。

getInboxData(id?) {
    this.inboxID = id;
    this.loadingData.next( // tells to start showing loading animation
    {
      showloading: true,
      clearDocuments: this.shouldClearDocuments()
    });

    this.getInboxCount();
    this.dashboardService.getInbox(id, this.page)
      .subscribe((response) => {
        for (const inbox of response['results']) {
          this.documents.push(inbox.document);
          // tells to stop showing loading animation
          this.loadingData.next({showloading: false, clearDocuments: this.shouldClearDocuments()});
        }
        if (response.next != null) {
          this.page++;
          // this.getInboxData(id);
        }else {
          this.page = 1; // reset
        }
        this.documentsData.next(response);

      });
  }
Run Code Online (Sandbox Code Playgroud)

我正在我的组件中订阅documentsData。以下是组件的代码。

ngOnInit() {
    this.dashboardDataService.getInboxData(); 
    this.dashboardDataService.documentsData
      .subscribe((response) => {
        this.isLoadingMoreResult = false; …
Run Code Online (Sandbox Code Playgroud)

observable rxjs angular2-observables angular

4
推荐指数
1
解决办法
5874
查看次数