2017-02-27 105 views
0

我想要使用此代碼在controller.js顯示按鈕點擊一個對話框:條形碼掃描儀關閉一次,彈出犯規顯示

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

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

功能($範圍,$ 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); 
    } 
); 
} 

}); 

}]) 

,但是當我在設備運行的應用程序,掃描儀的作品,但警告框,顯示細節不露面,和掃描儀一次檢測條形碼後關閉。可能是什麼問題呢?

+0

我想你正在實施它錯誤的方式。嘗試http://ngcordova.com/docs/plugins/barcodeScanner/ –

回答

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 
    }); 

問候提及。