【问题标题】:Subscribe to angular firestore collection with no need of real time updates订阅 Angular Firestore 集合,无需实时更新
【发布时间】:2017-12-17 11:32:14
【问题描述】:

目前,我使用 AngularFirestoreCollection 的 valueChanges() 函数从我的 ionic 应用程序订阅 Angular Firestore 集合。但是我不需要实时更新我的​​数据。我需要订阅时存在的数据。有没有办法做到这一点?

【问题讨论】:

    标签: angularjs ionic3 google-cloud-firestore


    【解决方案1】:

    最简单的方法是在获得所需数据后取消订阅。

     let tempSubscription: Subscription = this.callReturningObservable(params)
                  .subscribe(item => {
                    tempSubscription.unsubscribe();
                    tempSubscription = null;     // don't need this anymore
                    this.storeTheItem = item;
                  }, error => {
                    console.error("Error: " + error.message);
                  });
    

    【讨论】:

      【解决方案2】:

      使用 toPromise().then(data => data) 代替 subscribe()。这只会获取一次数据

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-04-09
        • 1970-01-01
        • 2020-07-03
        • 2013-02-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-08-21
        相关资源
        最近更新 更多