javascript - 如何使用 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 };
});
解决方案
this.store.pipe(select(fromAuth.selectErrorMessage)).pipe(skip(1))
将忽略当前值,只发出下一个值。
推荐阅读
- javascript - 在 Woocommerce 的产品标题中添加产品 ID 作为后缀
- javascript - 在浏览器中使用声音推送通知 (javascript)
- python - 函数内的临时 DataFrame 子集修改
- mysql - 如何编写 SQL 查询以按当前工资单中谁工作最多的降序显示工人
- python - 将 2 个一维数组排序为一维数组
- fusioncharts - 图例中悬停的工具提示
- next.js - 将 Shopify Polaris 链接与 Nextjs 链接连接起来
- google-apps-script - 如何使用超链接对 Google Sheet 范围内的每个单元格进行迭代并将批量照片发送到 Telegram?
- python - 如何在 Azure 的 score.py 中调用我的清理 python 脚本
- node.js - 特快路线申报