我试图将“费用”列表中每笔交易的“金额”值相加。
这是我的数据库:
订阅中的日志有效,总计1700,但是我无法从函数中获取“ this.expenseListTotal”的值以在其他组件中显示。如何返回“ this.expenseListTotal”值,以便可以在其他组件中使用它?
code . Filename.cs
答案 0 :(得分:0)
服务中:
getExpenseListTotals(budgetId: string) {
return new Promise(resolve => {
this.total = this.afd.list('users/' + this.cUser.uid + '/budgets/' + budgetId + '/expenses').subscribe((_data) => {
this.expenseListTotal = _data.reduce((sum, item) =>sum+item.amount,0);
resolve(this.expenseListTotal);
});
})
}
在组件中:
this.total = this.budgetService.getExpenseListTotals(this.budgetId);
this.total.then(function(value){
console.log(value)
});