Ionic 3:尝试区分“[object Object]”时出错
Ionic 3: Error trying to diff '[object Object]'
我想以循环的形式将FCM推送通知显示到首页。
但是,我收到此错误
HomePage.html:18 ERROR Error: Error trying to diff '[object Object]'. Only arrays and iterables are allowed(…)
对不起..在 Ionic 3(和打字稿)中仍然是新的,无论如何提前谢谢你
这是我的代码:
app.component.ts
// Receiving token from FCM
FCMPlugin.getToken(
(t) => {
console.log(t);
},
(e) => {
console.log(e);
}
);
// Receiving notification when app is in background
FCMPlugin.onNotification(
(infos) => {
this.dataProvider.fcmPassing(infos);
console.log(infos);
// Display notification when app on foreground
let basicAlert = this.alertCtrl.create({
title: infos.title,
subTitle: infos.body,
buttons: ['OK']
});
basicAlert.present();
},
(e) => {
console.log(e);
}
);
data.ts
// Calling FCM data
fcmReceiving() {
return this.storage.get('fcmData');
}
// Saving FCM data
fcmPassing(infos) {
this.storage.set('fcmData', infos);
}
home.ts
infos: Promise<any>;
public notis = [];
// Calling FCM data via DataProvider
this.dataProvider.fcmReceiving()
.then((info) => {
console.log('fcm data', info);
this.infos = info.title;
this.notis = info;
})
home.html
<ion-list>
<ion-item *ngFor="let noti of notis" (click)="passingFCM(infos)">Hello {{noti.title}}</ion-item>
</ion-list>
您评论说 notis 是一个数组,但您在代码示例中暗示检索到的 info 是一个对象:
console.log('fcm data', info);
this.infos = info.title;
this.notis = info;
在这种情况下,this.notis 不是数组。它是任何信息,在您的情况下它不是数组,因为它包含其他数据,例如 info.title
将this.notis设置为info
中的数组
我想以循环的形式将FCM推送通知显示到首页。 但是,我收到此错误
HomePage.html:18 ERROR Error: Error trying to diff '[object Object]'. Only arrays and iterables are allowed(…)
对不起..在 Ionic 3(和打字稿)中仍然是新的,无论如何提前谢谢你
这是我的代码:
app.component.ts
// Receiving token from FCM
FCMPlugin.getToken(
(t) => {
console.log(t);
},
(e) => {
console.log(e);
}
);
// Receiving notification when app is in background
FCMPlugin.onNotification(
(infos) => {
this.dataProvider.fcmPassing(infos);
console.log(infos);
// Display notification when app on foreground
let basicAlert = this.alertCtrl.create({
title: infos.title,
subTitle: infos.body,
buttons: ['OK']
});
basicAlert.present();
},
(e) => {
console.log(e);
}
);
data.ts
// Calling FCM data
fcmReceiving() {
return this.storage.get('fcmData');
}
// Saving FCM data
fcmPassing(infos) {
this.storage.set('fcmData', infos);
}
home.ts
infos: Promise<any>;
public notis = [];
// Calling FCM data via DataProvider
this.dataProvider.fcmReceiving()
.then((info) => {
console.log('fcm data', info);
this.infos = info.title;
this.notis = info;
})
home.html
<ion-list>
<ion-item *ngFor="let noti of notis" (click)="passingFCM(infos)">Hello {{noti.title}}</ion-item>
</ion-list>
您评论说 notis 是一个数组,但您在代码示例中暗示检索到的 info 是一个对象:
console.log('fcm data', info);
this.infos = info.title;
this.notis = info;
在这种情况下,this.notis 不是数组。它是任何信息,在您的情况下它不是数组,因为它包含其他数据,例如 info.title
将this.notis设置为info
中的数组