konstantinkrassmann / ngCordova-nfc

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

Problem getting ng-show to work on nfc event #8

Closed daveLC closed 7 years ago

daveLC commented 9 years ago

Having set up a basic cordova angular app and importing the ngCordova-nfc module, the following controller:

angular.module("RetailerApp.controllers.Main", ['ngCordova.plugins.nfc'])
.controller('MainController', function($scope, $cordovaNfc) {
     $cordovaNfc.then(function(nfcInstance){
          nfcInstance.addNdefListener(function(event) {
              $scope.customerId = getCustomerIdFromNfcTag(event.tag);
              alert ("Customer id read: " + $scope.customerId);
              $scope.customerDiv = true;
          });
    }); 
});

var getCustomerIdFromNfcTag = function (tag) {
    var ndefMessage = tag.ndefMessage;
    var fullMessage = JSON.stringify(ndefMessage);
    var payload = nfc.bytesToString(ndefMessage[0].payload).substring(3);
    return payload;
};

And a view with the following:

<body ng-app="RetailerApp" ng-controller="MainController">
    <div ng-show="customerDiv">
        <p>Customer: {{customerId}}</p>
    </div>
 </body

When scanning an nfc card the alert fires, but the div fails to show. Is there something getting in the way of the ng-show directive?

konstantinkrassmann commented 7 years ago

Not a problem about this repo / project, check stackoverflow ;)