Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

data parameter return undefined in click event #1151

Closed
hguldal opened this issue Nov 22, 2016 · 10 comments
Closed

data parameter return undefined in click event #1151

hguldal opened this issue Nov 22, 2016 · 10 comments

Comments

@hguldal
Copy link

hguldal commented Nov 22, 2016

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 ?

@SammyIsra
Copy link

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!

@rwillett
Copy link
Collaborator

This was also reported here #1138. @SammyIsra has the same solution as we used :)

Rob

@vjoao
Copy link

vjoao commented Dec 14, 2016

This should be in the docs =)

@rwillett
Copy link
Collaborator

rwillett commented Jan 5, 2017

Can this be closed now?

Rob

@SammyIsra
Copy link

I believe so, yes.

@rwillett
Copy link
Collaborator

rwillett commented Jan 7, 2017

Only you can close it 😃

Rob

@wuilmerj24
Copy link

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

@rwillett
Copy link
Collaborator

@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

@SammyIsra
Copy link

@rwillett I cannot close this

@rwillett
Copy link
Collaborator

rwillett commented Feb 6, 2017

You are correct, I should have referred to @hguldal, Apologies.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants