I 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 does not work for me.
I have a <textarea>
in my getMsg.html
file, when I enter something inside, the view is magically updated and it shows me the new values (after I receive a notification).
If I use the function getMessage()
directly, if it works for me.
What I have also tried, is to update / reload the view with:
this.navCtrl.setRoot( this.navCtrl.getActive().component );
but it does not work either.
Ionic: v3.4.0
Cordova: v7.0.1