konstantinkrassmann / ngCordova-nfc

Wrapper for the NFC functionality
MIT License
11 stars 4 forks source link

"nfc is not defined" error #5

Closed vanhumbeecka closed 9 years ago

vanhumbeecka commented 9 years ago

When trying to execute your example code from the readme.md file, I always get this error. Looking in the sources of your code, it seems this happens if the 'nfc' variable is not found. I've succesfully installed phonegap nfc, was able to run their example (with no ionic involved). But i just can't figure out how to get that 'nfc' variable visible in my controller.

Suggestions?

konstantinkrassmann commented 9 years ago

Hi,

I hope you'r running the app on a real (emulated) device, through nfc is getting injected only in a device env. 'nfc' is a window variable and will be injected by cordova.

Did you install the nfc plugin ? https://github.com/chariotsolutions/phonegap-nfc

vanhumbeecka commented 9 years ago

Yes, i'm running the app on a real, not emulated, device (my nexus 5) through the 'phonegap app'. I was able to run their non-angular example. I'm thinking maybe the nfc variable is called too soon (not instantiated yet) in the angular applications, although I use the $ionicPlatform.ready function. If I can locate the problem, i'll post it back.

vanhumbeecka commented 9 years ago

Hi, I found out what the problem was.

Apparently, when using the 'Phonegap App' to develop (using 'phonegap serve' in a console, connecting with the phonegap app), the NFC variable was never recognized. I suspect because the 'phonegap app' simply doesn't support nfc (yet?). Once I acctualy build it on my device ('ionic run') the nfc variable is recognized, and all works fine.