0

I able to get message which comes from FCM. But my criteria is to show a LocalNotifications. I able to create LocalNotifications. But problem is while I call the function is "onNotification" callbacks it does not work. Out side of the "onNotification" callbacks it work. I am sending my code here.

import { Component } from '@angular/core';
import { NavController,Platform } from 'ionic-angular';
import { LocalNotifications } from '@ionic-native/local-notifications';
declare var FCMPlugin: any;

@Component({
            selector: 'page-home',
            templateUrl: 'home.html'
           })
export class HomePage {

        constructor(public platform: Platform,private localNot:LocalNotifications) {
        this.onNotifon()
        }
   btnPushClicked(message:string)
   {
     this.platform.ready().then(() => {
     this.localNot.schedule({
                              text: message,
                               at: new Date(new Date().getTime() + 3600),
                              led: 'FF0000',
                            sound: null
                            });
                                     });
     }
    async onNotifon()
      {
         try{
             //this.btnPushClicked("Test Here Sucess ");//Is this area function work 
              await this.platform.ready();
             // FCMPlugin.onNotification()
               if(typeof(FCMPlugin) != 'undefined') {
              //alert("INSIDE FCMPlugin");
               FCMPlugin.onNotification(function(data){
               alert("INSIDE onNotification data:"+ data.message);
                console.log(data);
             this.btnPushClicked(data.message); //Is this area function not work 
            })
         }
        else
         {
           alert("FCMPlugin undefined");
         }
     }
     catch(e)
    {
       alert("e problem"+e )
    }

   }

  }

Data Comes From FCM

Error show while execute btnPushClicked()

Please some one suggest something so that I can solve it.

Jit Dasgupta
  • 57
  • 2
  • 12
  • Possible duplicate of [How to access the correct \`this\` inside a callback?](https://stackoverflow.com/questions/20279484/how-to-access-the-correct-this-inside-a-callback) – Suraj Rao Sep 14 '17 at 10:47
  • this answer in particular -https://stackoverflow.com/a/38931751/4826457 use arrow – Suraj Rao Sep 14 '17 at 10:48
  • I am the beginner. Every thing is out of reach. Please suggest some easy example. – Jit Dasgupta Sep 14 '17 at 10:51
  • Guys U are grate. Thanks for share your thought. Yes I just put the context in to another var and used in the callback instead direct "this". – Jit Dasgupta Sep 14 '17 at 11:22

0 Answers0