0
我嘗試更新一個陣列中後收到的通知從Onesignal像這樣:離子 - Onesignal - 論handleNotificationReceived不更新視圖
getMsg.ts:
getMsg = Array<Object> = [];
...
constructor(... private oneSignal: OneSignal ...) {
...
this.oneSignal.handleNotificationReceived().subscribe(() => {
this.getMessage();
console.log('handleNotificationReceived');
});
}
getMessage() {
this.getMsg.push({ text: 'some text' });
console.log('getMessage');
// Push is working
console.log(JSON.stringify(this.getMsg)); // [{"text":"some text"}]
}
getMsg.html:
...
<ion-list *ngFor="let m of getMsg">
<ion-item>
<p>{{ m.text }}</p>
</ion-item>
</ion-list>
...
但它沒有按預期工作。
我在我的getMsg.html
文件中有一個<textarea>
,當我輸入它時,視圖神奇地更新(在我收到通知之後)。
很明顯,如果我直接使用功能getMessage()
,它的工作原理。
我嘗試過,是更新/重裝的觀點:
this.navCtrl.setRoot(this.navCtrl.getActive().component);
,但沒有運氣。
Ionic: v3.4.0
Cordova: v7.0.1