2017-01-13 229 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