【问题标题】:listen to changes in the value of an observable监听 observable 值的变化
【发布时间】:2018-10-15 23:44:21
【问题描述】:

我正在尝试将 ionic 的加载控制器与 Firestore 查询一起使用。据我所知,这会返回一个 observable 并且还会监听查询值的变化。

但是有没有办法在函数中知道 observable 的值是否已经改变?因为现在加载程序会在每次点击时显示,即使没有任何更改,我希望加载程序仅在查询结果发生更改时显示。

这就是我想做的事

category(category){
  let loading = this.load.create({
    content: 'Please wait...'
  });



  this.selected = category;

    this.fsp.getCategory(category).subscribe(res => {
      if(res has changed){
         loading.present();
      this.data = this.group.groupEvents(res);
         loading.dismiss();
       } else(observable value remained the same) {
           this.data = this.group.groupEvents(res);
           }
    });

  }

【问题讨论】:

    标签: typescript ionic-framework observable


    【解决方案1】:

    我不太确定,因为我很久没有使用 Firestore,但是 也许您可以使用valueChanges() 获取“当前”值并将其存储在 prev var 中,并且每次订阅触发时,进行比较并采取相应措施。

    【讨论】:

      猜你喜欢
      • 2023-03-25
      • 1970-01-01
      • 1970-01-01
      • 2021-05-29
      • 1970-01-01
      • 2011-10-05
      • 1970-01-01
      • 2023-04-07
      • 1970-01-01
      相关资源
      最近更新 更多