2016-05-03 13 views
2

Ich habe diese Lösung im Visual Studio, wo ich ein Cordova Projekt erstelle. Ich habe auch ngCordova und das phonegap-plugin-barcodescanner Plugin installiert.phonegap angularjs barcodescanner

Ich habe ngCordova injiziert und machte diese Funktion:

$scope.scan = function() { 

    $cordovaBarcodeScanner.scan(
    function (result) { 
     alert("We got a barcode\n" + 
      "Result: " + result.text + "\n" + 
      "Format: " + result.format + "\n" + 
      "Cancelled: " + result.cancelled); 
    }, 
    function (error) { 
     alert("Scanning failed: " + error); 
    }); 

}; 

aber es funktioniert nicht auf: cordova.plugins

undefiniert ist

Was bin ich ??

Antwort

1

Cordova Plugins laufen nur auf echten Geräten oder Emulatoren.

Die scan() Methode ein Versprechen zurück:

$cordovaBarcodeScanner 
    .scan() 
    .then(function(barcodeData) { 
    // Success! Barcode data is here 
    console.log(barcodeData); 
    }, function(error) { 
    // An error occurred 
    console.log(error); 
    }); 

Wenn Sie möchten, testen Sie Ihre App im Browser laufen Sie ein Modell wie diese verwenden:

if (!window.cordova){ 
    window.cordova = { 
    plugins: { 
     barcodeScanner: { 
     scan: function (success, error) { 
      var code = window.prompt("Enter barcode value (empty value will fire the error handler):"); 
      if(code) { 
      var result = { 
       text:code, 
       format:"Fake", 
       cancelled:false 
      }; 
      success(result); 
      } else { 
      error("No barcode"); 
      } 
     } 
     } 
    } 
    }; 
} 
Verwandte Themen