【问题标题】:Get the value only if a new value comes after subscribing仅当订阅后出现新值时才获取该值
【发布时间】:2016-06-30 01:20:32
【问题描述】:

我正在使用 ngrx/store。

this.store
      .select(s => s.products && s.products.name)
      .filter(name => !!name)
      .subscribe(name => {
        // Now if there is a `name` in the store, it will run immediately
        // However, I want to get the `name`, only if a new value comes after subscribing
        console.log(name);
      });

我尝试在.subscribe 之前添加.publish(),但我无法获得任何值。

我如何才能获得name,只有在订阅后出现新值?谢谢

【问题讨论】:

    标签: angular typescript rxjs ngrx


    【解决方案1】:

    当您订阅时,将返回商店的当前状态。如果您不想要当前状态,则可以跳过第一个响应。 this.store.select(...).skip(1)

    【讨论】:

      【解决方案2】:

      为此,您需要了解以下内容:

      • 热与冷可观察对象
      • 背压(在您的情况下公差为 0)
      猜你喜欢
      • 1970-01-01
      • 2021-07-30
      • 2018-10-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-05
      • 1970-01-01
      相关资源
      最近更新 更多