1
Stroy: 我正在做一个带有appery.io的小型移动应用程序,它将扫描二维码并根据值隐藏/显示一个按钮。带回调更新Ionic UI元素
问题:(:隐藏名称)布尔值:当我改变可变 按钮将隐藏
$scope.QRscanner = function (_callback) {
cordova.plugins.barcodeScanner.scan(
function (result)
{
if(result.cancelled!=1){
$scope.hide = false;
$scope.scannedValue = result.text;
_callback(false);
}
else
{ _callback(true);
alert("Operation cancelled");
}
},
function (error) {
$scope.hide = true;
},
{
preferFrontCamera : true, // iOS and Android
showFlipCameraButton : true, // iOS and Android
showTorchButton : false, // iOS and Android
torchOn: false, // Android, launch with the torch switched on (if available)
prompt : "Place a barcode inside the scan area", // Android
resultDisplayDuration: 500, // Android, display scanned text for X ms. 0 suppresses it entirely, default 1500
formats : "QR_CODE,PDF_417", // default: all but PDF_417 and RSS_EXPANDED
orientation : "landscape", // Android only (portrait|landscape), default unset so it rotates with the device
disableAnimations : true // iOS
}
);
}
这是回调函数;
$scope.Callback = function (result)
{
alert("result"+result);
$scope.hide=result;
}
最后我会调用这个函数QRscanner在带参数的回调函数名NG单击。
QRscanner(Callback);
我很新的离子+ angular.kind帮助将不胜感激。
感谢您的回复;我已经修复这个,但有点不同的方式。我不得不打电话给$ scope。$ apply();在回调更新UI – mzonerz
您可以添加ngCordova/Ionic Native到您的项目中,他们有AngularJS包装,并更容易使用所有原生插件。使用ngCordova,您不需要手动执行apply(),因为所有服务都会返回promise。你应该看看他们。 http://ngcordova.com/docs/ –