我正在构建一个使用Angular2,Firebase和AngularFire2的实验性应用程序。 这是我的数据是什么样子:我想计算Firebase中的ShoppingCart与Angularfire2的总和
{
"ShoppingCartItem":
{
"item1":{
"quantity": 2,
"productId": "abc"
},
"item2":{
"quantity": 1,
"productId": "bcd"
}
}
"Product"
{
"abc":{
"name": "product1",
"price": 5
},
"bcd":{
"name": "product2",
"price": 6
}
}
}
下面是我的cart.ts
this.items = this.af.database.list('ShoppingCartItem')
.map(carts => {
return carts.map(item => {
item.product = this.af.database.object(`Product/${item.productId}`);
return item;
});
});
下面是我cart.html
<table>
<tbody>
<tr *ngFor="let item of (items | async)">
<td>{{(item.product | async)?.name}}</td>
<td><input type="text" name="quantity" [(ngModel)]="item.quantity" size="1" class="form-control"></td>
<td>{{(item.product | async)?.price | number: '.2'}}</td>
<td>{{(item.product | async)?.price * item.quantity | number: '.2'}}</td>
</tr>
</tbody>
<tfoot>
<tr>
<td colspan="2" class="text-right">
<strong>Total :</strong>
</td>
<td colspan="2" class="text-left">
?????????
</td>
</tr>
</tfoot>
我想计算的总和ShoppingCart。所以我想要找到数据显示的(2 * 5)+(1 * 6)= 16的值。我该怎么做。
太棒了!我正在开展一个项目,我将需要很多RXJS。感谢你,我相信我可以学到一些东西。再次感谢你。 –