2017-01-13 157 views
0

我想訪問字段類別和specCategory。我申請了*ngFor="let x of data" {{x._id.category}},但它不起作用。它出什麼問題了?通過Angular訪問對象

我正在使用聚合功能來對這些類別進行分組。

$group: { 
       _id: { 
     category: "$category", 
     specCategory: "$specCategory" 
    }, 


       min: {$min: '$price'}, 
       max: {$max: 500}, 
       total:{$sum:1} 
      } 

結果:

[ { _id: { category: 'Wasser & Wind', specCategory: 'Surfen' }, min: 49, max: 500, total: 1 }, { _id: { category: 'Reisen', specCategory: 'Hotel' }, min: 49, max: 500, total: 1 } ] 

我將需要訪問類別,specCategory和總價值

+2

那是因爲你的對象不是一個數組。 Angular2不支持迭代遍歷映射,只能遍歷數組 – devqon

回答

1

你錯過了關閉大括號。

{ _id: { category: 'Reisen', specCategory: 'Hotel' }, 

應該

{ _id: { category: 'Reisen', specCategory: 'Hotel' }}, 

我加plunker看看文件上:應用程序/ app.component.ts

+0

好的,完整的數據結構看起來像這樣[{_id:{category:'Wasser&Wind',specCategory:'Surfen'}, min:49, max: 500, total:1}, {_id:{category:'Reisen',specCategory:'Hotel'}, min:49, max:500, total:1}] – Tony