I tried to update an array after received a notification from Onesignal like so:
getMsg.ts: (simplified)
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>
...
But it doesn’t work as expected.
I have an <textarea>
in my getMsg.html
file, when I type in it, the view magically updates (after I receive a notification).
And obviously, if I use the function getMessage()
directly, it works.
What I tried too, is to update/reload the view with:
this.navCtrl.setRoot( this.navCtrl.getActive().component );
but with no luck.
Ionic: v3.4.0
Cordova: v7.0.1