条形码扫描器立刻关闭,弹出窗口没有显示

时间:2017-02-27 08:25:03

标签: angularjs ionic-framework cordova-plugins barcode-scanner

我试图在控制器中使用此代码点击按钮时显示警告框:

angular.module('app.controllers', ['ionic','ngCordova'])

.controller('page1Ctrl', ['$scope', '$stateParams', '$cordovaBarcodeScanner'

函数($ scope,$ stateParams,$ cordovaBarcodeScanner){

document.addEventListener("deviceready", function () {

$scope.scanCode = 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);
   }
 );
}

});

}])

但是当我在设备中运行应用程序时,扫描仪正常工作,但显示详细信息的警告框不会显示,扫描仪在检测到条形码后立即关闭。可能是什么问题?

1 个答案:

答案 0 :(得分:0)

按照Documentation

中提到的方式尝试
$cordovaBarcodeScanner
  .scan()
  .then(function(barcodeData) {
    // Success! Barcode data is here
    alert("We got a barcode\n" +
        "Result: " + barcodeData.text + "\n" +
        "Format: " + barcodeData.format + "\n" +
        "Cancelled: " + barcodeData.cancelled);
  }, function(error) {
    // An error occurred
  });

问候。