I have tried to update an array after receiving a notification from Onesignal:
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' );
// Funciona
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's not working.
I have one <textarea>
in my getMsg.html
, when I put something in it, the view magically updates and shows me the new values (after I get notified).
If I use the function getMessage()
directly, it works for me.
What I have tried too, is to update/reload the view with:
this.navCtrl.setRoot( this.navCtrl.getActive().component );
but it doesn't work either.
Ionic: v3.4.0
Cordova: v7.0.1
After a few days of racking my brain, I was able to solve it with the help of the following page:
Translated would be ( google translate ):
Solution code: