I have two strange problems:
1.- I have a modal popup, when I open the popup, I call the controller and wait for the user to tap a tag. The first time it taps, I can hear the sound BUT it doesn't grab any details from the tag. The second and subsequent times, it does. It just happens the first time I tap a tag.
2.- The second problem is that when I scan a second time, it duplicates the result. Let me show you some code that explain my problem:
<ion-content>
...
</ion-content>
<ion-footer-bar class="bar-positive" ng-if="showFooter" ng-controller="NFCCtrl">
<div>
<button ng-click="openModal(1)" class="button button-icon">
TEST
</button>
</div>
</ion-footer-bar>
<script id="nfc.html" type="text/ng-template">
<div class="modal">
<header>
<h1 class="title">NFC</h1>
<div class="button button-clear" ng-click="closeModal(1)"><span class="icon ion-close"></span></div>
</header>
<ion-content>
<div>
...
</div>
</ion-content>
</div>
</script>
.controller('NFCCtrl', function ($scope, $ionicModal, $ionicPlatform) {
$ionicModal.fromTemplateUrl('nfc.html', {
id: '1',
scope: $scope,
backdropClickToClose: false,
animation: 'slide-in-up'
}).then(function (modal) {
$scope.oModal1 = modal;
});
$scope.openModal = function (index) {
if (index == 1) {
$scope.oModal1.show();
try {
navigator.geolocation.getCurrentPosition(function (result) {
$scope.position = result.coords;
$scope.$apply();
alert('modal opened!');
//////////////////////////
nfc.addNdefListener(function (nfcEvent) {
var tag = nfcEvent.tag,
ndefMessage = tag.ndefMessage;
var ndef_value = nfc.bytesToString(ndefMessage[0].payload).substring(1);
var some_value = ndefMessage[0]["payload"];
var string_value = nfc.bytesToString(some_value);
alert('hello world!');
// Insert value to DB
...
When the modal popup opens, I can see the alert('modal opened!');
. Then I tap the NFC and I get the alert('hello world!');
. So far so good, now I tap another tag and I get the alert('hello world!');
TWICE. Then I tap again, and I get it 3 times, another tap and then 4 times and so on. I haven't been able to figure out why is adding duplicates :(