我正在構建一個使用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。感謝你,我相信我可以學到一些東西。再次感謝你。 –