Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/459.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用回调更新离子UI元素_Javascript_Angularjs_Ionic Framework_Appery.io - Fatal编程技术网

Javascript 使用回调更新离子UI元素

Javascript 使用回调更新离子UI元素,javascript,angularjs,ionic-framework,appery.io,Javascript,Angularjs,Ionic Framework,Appery.io,Stroy: 我正在用appery.io做一个小的移动应用程序,它将扫描二维码并根据值隐藏/显示一个按钮 问题: 更改变量(名称:hide)布尔值时,按钮将隐藏: $scope.QRscanner = function (_callback) { cordova.plugins.barcodeScanner.scan( function (result) { if(result.cancelled!=1){

Stroy: 我正在用appery.io做一个小的移动应用程序,它将扫描二维码并根据值隐藏/显示一个按钮

问题: 更改变量(名称:hide)布尔值时,按钮将隐藏:

$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单击中调用此QRscanner函数

QRscanner(Callback);

我对ionic+angular非常陌生。非常感谢您的帮助。

假设您有以下两个按钮:

<button ng-click="QRscanner()"> Scan Code </button>
<button ng-hide="hide"> Button to Hide </button>

谢谢你的答复;我已经解决了这个问题,但方法有点不同。我必须调用$scope。$apply();在回拨更新UI时,您可以将ngCordova/Ionic Native添加到您的项目中,它们具有AngularJS包装器,并使所有本机插件更易于使用。使用ngCordova,您不需要手动执行apply(),因为所有服务都会返回承诺。你应该看看他们。
$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
        }
    );
}