无法从 ngrx 商店取消订阅

问题描述 投票:0回答:1

我对接下来的情况真的很困惑。也许我不明白浏览器中的某些内容。

我有一个订阅可以从我的 ngrx/实体商店中选择。效果很好。代码如下。

constructor(private store: Store<State>) {
    this.formConfiguration();

    this.moveTradeSubscription = this.store.select(selectTradeEntities).subscribe((tradeDictionary) => {
      const tradeFromStore = Object.values(tradeDictionary)[0];
      if (tradeFromStore !== null && tradeFromStore !== undefined && tradeFromStore.Stage === 2) {
        // this.store.dispatch(removeTrade());
        console.log('remove from panel draft stage 2');
        this.tradeDraftPanelEmitter.emit(tradeFromStore.TradeId);
        this.store.dispatch(deleteTrade({ TradeId: tradeFromStore.TradeId }));
      }
    })
  }

你可以看到我有

console.log('remove from panel draft stage 2');

还有我

unsubscribe
来自我的
Subscription

ngOnDestroy(): void {
  this.moveTradeSubscription.unsubscribe();
}

但是我总是在组件销毁后重复这个

console.log('remove from panel draft stage 2');
,最奇怪的是在重新加载并关闭并再次打开浏览器后。

重新加载我的页面后。

据我了解,我没有

unsubscribe

angular ngrx ngrx-entity
1个回答
0
投票

输入 moveTradeSubscription !: 订阅

订阅来自rxjs

和 第二个用

this.store.select(selectTradeEntities).pipe(take(1)).subscribe() => ...继续使用您的代码 你将根据你的情况使用 take , takeUntill

© www.soinside.com 2019 - 2024. All rights reserved.