【问题标题】:Map and Subscribe in the new AngularFire在新的 AngularFire 中映射和订阅
【发布时间】:2018-01-25 23:31:38
【问题描述】:

我安装了新版本的 Angularfire,我喜欢你现在访问地图和订阅方法的新方法。

getEinnahmen(){
this.einnahmen = 0;

this.db.list("/Budget",{query:{
     orderByChild:'ausgabe',
     equalTo: 'Einnahme'
   }}).map(items => items.reduce((acc, item) => acc + item.betrag, 0))
   // Log the total
     .subscribe(total => {
       console.log(total);
       this.einnahmen = total + 2500;
     });

    return this.einnahmen;

  }

我现在如何获取数据条目的总和,因为系统无法在 FirebaseListObservable 上找到地图或订阅方法。

【问题讨论】:

  • 您是否导入了命名空间?导入'rxjs/add/operator/map';

标签: javascript angular firebase firebase-realtime-database angularfire2


【解决方案1】:
import 'rxjs/add/operator/map';

这是测试您是否获取数据然后尝试映射它的基本示例

this.AngularFire.database.list("/Budget/")
.map((items) => { //first map
 console.log(items);
 return items.map(item => { //second map
  console.log(items);
  console.log(item);
})

})

在 Html 中,您可以使用 async,这样您就不必担心取消订阅它。当您使用 async 时,它会自行取消订阅。

【讨论】:

    猜你喜欢
    • 2022-01-06
    • 1970-01-01
    • 2018-09-21
    • 1970-01-01
    • 1970-01-01
    • 2019-03-15
    • 2012-08-12
    • 1970-01-01
    • 2019-09-06
    相关资源
    最近更新 更多