活动清单:
export class HomePage {
private socket = null;
private event_list = [];
constructor(public http: Http) {
this.http = http;
this.event_list = [{"payload": {"action": "create", "pk": 667, "model": "photogallery.image", "data": {"confidence": "93.62", "detect": false, "description": "a gate in front of a fence", "timestamp": "2017-09-12T17:26:43.029Z", "image": "gallery/PICT0609_X4Fpw9D.JPG", "detect_type": null, "device": 1}}, "stream": "intval"}]
然后在模板中重复事件:
<ion-list>
<ion-item ng-repeat="event in event_list">
<ion-thumbnail item-start>
<img src="img/thumbnail-totoro.png">
</ion-thumbnail>
<h2>{{ event.payload.data }}</h2>
<p>{{ event.payload.data.description }}</p>
<button ion-button clear item-end>View</button>
</ion-item>
</ion-list>
然后错误:
错误类型错误:无法读取属性&#39;有效负载&#39;未定义的
但是在模板中,当我执行{{event}}时,它会显示在模板中:
[object Object]
那为什么不定义?
答案 0 :(得分:2)
如果您使用Ionic 2.请使用*ngFor
代替ng-repeat
<ion-list>
<ion-item *ngFor="let event of event_list">
<ion-thumbnail item-start>
<img src="img/thumbnail-totoro.png">
</ion-thumbnail>
<h2>{{ event.payload.data }}</h2>
<p>{{ event.payload.data.description }}</p>
<button ion-button clear item-end>View</button>
</ion-item>
</ion-list>