首页 > 解决方案 > 如何使用 NgRx 选择作为主题而不是 BehaviorSubject

问题描述

有没有办法将 NgRx 选择视为 aSubject而不是BehaviorSubject

我不想在第一次订阅时执行下一个(默认行为)。相反,只想在状态更改时执行它。

this.store.pipe(select(fromAuth.selectErrorMessage)).subscribe((message) => {
      /* This content is executed the first time the subscription is made, 
         and after that is executed everytime the state change */
      this.isLoading = false;     
      this.errorMessage = { ...message };
});  

标签: javascriptangularngrx

解决方案


this.store.pipe(select(fromAuth.selectErrorMessage)).pipe(skip(1))

将忽略当前值,只发出下一个值。


推荐阅读