Closed hguldal closed 7 years ago
notification.data
is a JSON string. In your case, that variable looks like this:
'{"value":"key"}'
Or something in that style. To be able to access it like an object, you have to use
var data = JSON.parse(notification.data);
console.log(data.value) //This would output 'key'
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse
Hope that helps!
This was also reported here #1138. @SammyIsra has the same solution as we used :)
Rob
This should be in the docs =)
Can this be closed now?
Rob
I believe so, yes.
Only you can close it 😃
Rob
Hello I have a similar problem but with ionic 2. I have this variable public clickNotification: boolean = false;
Which must be changed to true when clicking on the notification: LocalNotifications.on ("click", function (notification) { Console.info ("After the click" + this.clickNotification); });
And the console displays undefined
@wuilmerj24
Your issue seems to bear no resemblance to the OP issue. I suggest you fill out the template in #1188 and raise a new issue and lets close this down.
Rob
@rwillett I cannot close this
You are correct, I should have referred to @hguldal, Apologies.
cordova.plugins.notification.local.schedule({ id: Math.floor((Math.random() * 1000000) + 1), title:'title', text:'text', data:{value:'key'} });
cordova.plugins.notification.local.on("click", function (notification) { alert(notification.data.value); //print undefined
}); notification.data.value return undefined why ?