我试图在控制器中使用此代码点击按钮时显示警告框:
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);
}
);
}
});
}])
但是当我在设备中运行应用程序时,扫描仪正常工作,但显示详细信息的警告框不会显示,扫描仪在检测到条形码后立即关闭。可能是什么问题?
答案 0 :(得分:0)
$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
});
问候。