带角火焰基地的科尔多瓦扫描仪

时间:2016-02-08 23:07:01

标签: cordova ionic-framework firebase angularfire

我正在使用cordova条码扫描器

请有人告诉我如何将我在firebase中的json文件中的数据链接到扫描程序,这样当用户扫描产品时数据将会出现在前端

我有以下代码:

                scan html 

            <ion-view view-title="Scan">
            <ion-nav-buttons side="left">
            <button class="button button-icon button-clear ion-navicon"
             ng-click="openMenu()"></button>
         </ion-nav-buttons>
          <ion-nav-buttons side="right">
           <button class="button button-icon button-clear ion-share" 
            ng-click="openRightMenu()"></button>
           </ion-nav-buttons>
               <ion-content class="has-subheader padding">
        <a class="button button-positive button-block button-outline
          icon-left  ion-qr-scanner" ng-click="scan()">Scan</a> 
           {{error || barcodeData}}
             </ion-content>
            </ion-view>


              controller.js 

      .controller('PrefCtrl', function($scope, Loader, 
           FirebaseRef,   $rootScope, $location) {
          var authData = $rootScope.authData;
         $scope.preferences = [];
           $scope.pref = {
         text: ''
            };
         if (!authData) {
    $location.path('/login');
    return;
    }

    Loader.showLoading('Fetching Preferences...');

        FirebaseRef.child("users")
     .child(authData.uid)
    .on('value', function(snapshot) {

        Loader.hideLoading();
        $scope.preferences = (snapshot.val() ? snapshot.val().preferences:
            []) || [];
           });

       $scope.savePref = function() {
     $scope.preferences.push($scope.pref.text);
    FirebaseRef
        .child("users")
        .child(authData.uid)
        .set({
            "preferences": $scope.preferences
        });

    $scope.pref.text = '';
   }

   })


  .controller('ScanCtrl', function($scope, Loader, FirebaseRef,
     $rootScope, $location, $cordovaBarcodeScanner) {


    var authData = $rootScope.authData;
    var matchedAllergies = [];

    if (!authData) {
    $location.path('/login');
    return;
    }

     Loader.showLoading('Fetching Preferences...');

     FirebaseRef
    .child("users")
    .child(authData.uid)
    .on('value', function(snapshot) {

        Loader.hideLoading();
        $scope.preferences = (snapshot.val() ? snapshot.val().preferences:
         []) || [];
    });

     $scope.scan = function() {
    $cordovaBarcodeScanner
        .scan()
        .then(function(barcodeData) {
            // Success! Barcode data is here
            $scope.barcodeData = barcodeData;

            //pick the value from barcodeData and
            // barcodeData.text

            var barcode = barcodeData.text;

            // make a call to Firebase to /products and 
            // pass the barcode to get its info
            // ->
            var product = {
                "name" : "Nacho Cheese Sauce - Discovery",
                "barcode": "5018420420419",
                "allergies": ["Peanuts, Sesame seeds, Treenut"],
                "ingredients": "Water, cheddar cheese 15%, cream",
                "suitable to consume" : "Okay for you!, Not for you!"
            };

            var product = {
                "name": "nairns - gluten free wholegrain crackers",
                "barcode": "0612322030070",
                "allergies": ["Milk, Nuts, Avenin, gluten"],
                "ingredients": "Wholegrain Oats (86%)",
                "suitable to consume": "Okay for you!, Not for you!"
            };

            for (var i = 0; i < $scope.preferences.length; i++) {
                for (var j = 0; j < product.allergies.length; j++) {
                    if ($scope.preferences[i] === product.allergies[j]) {
                        matchedAllergies.push($scope.preferences[i]);
                    }
                };
            };

            // If matchedAllergies.length > 0, he is allergic to
            // matchedAllergies

        }, function(error) {
            // An error occurred
            $scope.error = error;
        });
        }
       })

请告诉我接下来的步骤

谢谢

尔杰斯

0 个答案:

没有答案