2

cordovaNativeStoragebarcodeScannerプラグインを使用しています。スキャン後に角が印刷されないqr

キャプチャが正常に動作し、QRCodeが届きましたが、何らかの理由で角度が印刷されません。

私のコードで多くの作業をした後、有効なコールバックを実行できないため、角度でデータをバインドして印刷できます。

ここにコードを貼り付けます。

read.js

(function() { 
    'use strict'; 

    var read = angular.module('app.read', ['monospaced.qrcode']); 

    read.controller('ReadController', [ 
    function() { 

     var data = this; 

     var qr = function(string) { 
     data.code = string; 
     console.log(string); 
     }; 

     cordova.plugins.barcodeScanner.scan(
     function(result) { 
      if (!result.cancelled) { 
      if (result.format === "QR_CODE") { 
       (function(cb) { 
       cb(result.text); 
       })(qr); 
       NativeStorage.getItem("historic", function(d) { 
       var storage = JSON.parse(d); 
       storage.push(result.text); 
       NativeStorage.setItem("historic", JSON.stringify(storage), function(response) {}, function(e) { 
        console.log(e); 
       }); 
       }, function(e) { 
       window.alert("Scanning failed: " + e); 
       }); 
      } 
      } 
     }, 
     function(e) { 
      window.alert("Scanning failed: " + e); 
     }, { 
      "preferFrontCamera": true, // iOS and Android 
      "showFlipCameraButton": true, // iOS and Android 
      "prompt": "Place a barcode inside the scan area", // supported on Android only 
      "formats": "QR_CODE,PDF_417", // default: all but PDF_417 and RSS_EXPANDED 
      "orientation": "portrait" // Android only (portrait|landscape), default unset so it rotates with the device 
     } 
    ); 
    } 
    ]); 

}()); 

read.html

<div ng-controller="ReadController as myRead"> 
    <qrcode version="5" error-correction-level="H" size="200" data="{{myRead.code}}" href="{{myRead.code}}"></qrcode> 
    <a href="{{myRead.code}}">{{myRead.code}}</a> 
</div> 

ちょうど私が前に行っているいくつかの追加のテストを追加し、私はちょうどbarcodeScanner.scanプロセスを逃したし、私はちょうどストレージをしました次のように表示します。

NativeStorage.getItem("historic", function (d) { 
    var storage = JSON.parse(d); 
    storage.push('https://google.es'); 
    data.code = 'https://google.es'; 
    NativeStorage.setItem("historic", JSON.stringify(storage), function (response) {}, function (e) { 
     console.log(e); 
    }); 
}, function (e) { 
    window.alert("Scanning failed: " + e); 
}); 

私はどこが間違っているかを教えてください。

アドバイスありがとうございます。

答えて

2

cordova.plugins.barcodeScanner.scanのコールバックがAngularJSのダイジェストサイクルをトリガーしないことは、ダーティチェックが実行されず、変更が検出されず、UIが更新されないことを意味します。

$applyの成功コールバックでコードをラップしてみてください。

function(result) { 
    $scope.$apply(function() { 
    if (!result.cancelled) { 
     if (result.format === "QR_CODE") { 
     (function(cb) { 
      cb(result.text); 
     })(qr); 
     NativeStorage.getItem("historic", function(d) { 
      var storage = JSON.parse(d); 
      storage.push(result.text); 
      NativeStorage.setItem("historic", JSON.stringify(storage), function(response) {}, function(e) { 
      console.log(e); 
      }); 
     }, function(e) { 
      window.alert("Scanning failed: " + e); 
     }); 
     } 
    } 
    }); 
} 
+0

あなたの高速応答をありがとう!今は期待どおりに動作します。実際、私の話題は、この他の投稿で同じことが分かったので重複してマークする必要があります:http://stackoverflow.com/questions/27582403/how-to-access-scope-from-async-callback正直言って、あなたが通常は「角張っている」ように働かないと思う最後のこと。 – DevStarlight

+0

あなたは大歓迎です:) – tasseKATT

関連する問題