0
votes

Using the ngCordova Barcode Scanner i am storing the barcode number and the barcode format in variables to output them in the app view. I wan't to be able to scan multiple barcodes which have to update the stored variable every time writing out the new barcode number and format. But when I scan multiple barcodes it just keeps on appending "Barcode: + barcodeNumber " instead of replacing. I cannot figure out what I am doing wrong. The app screenshot shows the problem.

App screenshot image

Here's my index.html code:

<!DOCTYPE html>
<html>
 <head>
   <meta charset="utf-8">
   <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
   <title></title>

   <link href="lib/ionic/css/ionic.css" rel="stylesheet">
   <link href="css/style.css" rel="stylesheet">

   <!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
   <link href="css/ionic.app.css" rel="stylesheet">-->

   <!-- ionic/angularjs js -->
   <script src="lib/ionic/js/ionic.bundle.js"></script>

   <!-- cordova script (this will be a 404 during development) -->
   <script src="js/ng-cordova.min.js"></script>
   <script src="cordova.js"></script>

   <!-- your app's js -->
   <script src="js/app.js"></script>
 </head>
 <body ng-app="starter">

   <ion-pane>
     <ion-header-bar class="bar-stable">
       <h1 class="title">Barcode Scanner</h1>
     </ion-header-bar>
     <ion-content ng-controller="barcodeController">
           <button class="button button-full button-positive" ng-click="scanBarcode()">
            Scan Now
           </button>
           <div class="card">
               <div class="item item-divider">Barcode Data</div>
               <div class="item item-text-wrap">Barcode: {{barcodeNumber}}</div>
               <div class="item item-text-wrap">Format: {{barcodeFormat}}</div>
           </div>
      </ion-content>
    </ion-pane>
  </body>
</html>

Here's my app.js code:

// Ionic Starter App

// angular.module is a global place for creating, registering and retrieving Angular modules
// 'starter' is the name of this angular module example (also set in a <body> attribute in index.html)
// the 2nd parameter is an array of 'requires'

var ionScanner = angular.module('starter', ['ionic', 'ngCordova'])

.run(function($ionicPlatform) {
  $ionicPlatform.ready(function() {
    if(window.cordova && window.cordova.plugins.Keyboard) {
      // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
      // for form inputs)
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);

      // Don't remove this line unless you know what you are doing. It stops the viewport
      // from snapping when text inputs are focused. Ionic handles this internally for
      // a much nicer keyboard experience.
      cordova.plugins.Keyboard.disableScroll(true);
    }
    if(window.StatusBar) {
      StatusBar.styleDefault();
    }
  });
})

ionScanner.controller("barcodeController", function($scope, $cordovaBarcodeScanner) {

    $scope.scanBarcode = function() {
        $cordovaBarcodeScanner.scan().then(function(barcodeData){
            if (barcodeData.cancelled == 1){
                // Do nothing
            }else{
                // Assign barcode data
                $scope.barcodeNumber = "";
                $scope.barcodeNumber = barcodeData.text;
                $scope.barcodeFormat = barcodeData.format;
            }
         }, function(error){
            console.log("Error: " + error);
        });
    }   
});
1
I reproduced your project...it is odd...it's working perfectly fine on android. I changed a few things, but couldn't get it working on iOs. Hope, someone can solve this :) it's especially strange, because not only the variable is repeated but the whole "Barcode: ..." expression?! - Sunny Onesotrue
It's very odd, it doesn't matter what I try, I always end up with the same strange error... - user5086762

1 Answers

0
votes

So, it turned out that this error/bug was a result of the iOS automated phone number recognition. I solved the issue by adding a no format for phone numbers.

<meta name="format-detection" content="telephone=no">