2017-11-30 12 views
1

以下のコードは、すべて私の項目の数量が表示されていない私のfirebaseデータベースをループされていない、それだけで最初の項目私のコードは

import {ShoppingCartItem} from './shopping-cart-item'; 
 

 
export class ShoppingCart { 
 
    constructor(public items: ShoppingCartItem[]) {} 
 

 
    get totalItemsCount() { 
 
    let count = 0; 
 
    for (const productId in this.items) { 
 
     if (this.items.hasOwnProperty(productId)) { 
 
     count += this.items[productId].quantity; 
 
     return count; 
 
     } 
 
    } 
 
    } 
 

 
}

答えて

1

を表示しています、次のように変更します。

get totalItemsCount() { 
    let count = 0; 
    for (const productId in this.items) { 
     if (this.items.hasOwnProperty(productId)) { 
     count += this.items[productId].quantity;   
     } 
    } 
    return count; 
    }