故事: 我正在使用 appery.io 制作小型移动应用程序,它将扫描二维码并根据值隐藏/显示按钮。
问题: 当我更改变量(名称:隐藏) bool 值时按钮将隐藏:
$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;
}
最后我将在 ng-click 中使用参数回调函数名称调用此 QRscanner 函数。
QRscanner(Callback);
我对 ionic + Angular 很陌生。非常感谢您的帮助。
最佳答案
假设您有以下两个按钮:
<button ng-click="QRscanner()"> Scan Code </button>
<button ng-hide="hide"> Button to Hide </button>
如果您在同一个 Controller 中拥有两个按钮,则无需将回调作为参数发送,只需调用该函数即可:
$scope.hide = false;
function Callback(result) {
alert("result" + result);
$scope.hide = result;
}
$scope.QRscanner = function() {
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
}
);
}
关于javascript - 使用回调更新 Ionic UI 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41483469/