angular2如何打印对象数组的值

时间:2016-05-26 11:35:10

标签: typescript angular

我想打印一个值=>数组的id看起来像这样:

locations = [
    {id: '1',  lat: 51.5239935252832,    lng:  5.137663903579778,   content: 'Kids Jungalow (5p)'},
    {id: '2',  lat: 51.523853342911906,  lng:  5.1377765563584035,  content: 'Kids Jungalow (5p)'},
    {id: '3',  lat: 51.5237298485607,    lng:  5.137969675407476,   content: 'Kids Jungalow (5p)'},
    {id: '4',  lat: 51.52355628836575,   lng:  5.138066234932012,   content: 'Kids Jungalow (5p)'},
    {id: '5',  lat: 51.52340275379578,   lng:  5.138211074218816,   content: 'Kids Jungalow (5p)'},
    {id: '6',  lat: 51.523199152806626,  lng:  5.138382735595769,   content: 'Kids Jungalow (5p)'},
    {id: '7',  lat: 51.5229955509073,    lng:  5.138511481628484,   content: 'Kids Jungalow (5p)'},
];

在我的html模板中,我写的是:<h1 *ngFor="#location of locations">{{locations.id}}</h1>

但它没有显示出什么问题?

1 个答案:

答案 0 :(得分:2)

//检查您是否正在创建本地变量位置

<h1 *ngFor="#location of locations">**{{location.id}}**</h1>