ionic framework - cordova scanner with angular fire firebase -
i using cordova barcode scanner
please can tell me how link data json file in firebase scanner when user scans product data come front end
i have following code :
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 here $scope.barcodedata = barcodedata; //pick value barcodedata , // barcodedata.text var barcode = barcodedata.text; // make call firebase /products , // pass barcode info // -> var product = { "name" : "nacho cheese sauce - discovery", "barcode": "5018420420419", "allergies": ["peanuts, sesame seeds, treenut"], "ingredients": "water, cheddar cheese 15%, cream", "suitable consume" : "okay you!, not you!" }; var product = { "name": "nairns - gluten free wholegrain crackers", "barcode": "0612322030070", "allergies": ["milk, nuts, avenin, gluten"], "ingredients": "wholegrain oats (86%)", "suitable consume": "okay you!, not you!" }; (var = 0; < $scope.preferences.length; i++) { (var j = 0; j < product.allergies.length; j++) { if ($scope.preferences[i] === product.allergies[j]) { matchedallergies.push($scope.preferences[i]); } }; }; // if matchedallergies.length > 0, allergic // matchedallergies }, function(error) { // error occurred $scope.error = error; }); } }) please can tell me next steps
thanks
jess
Comments
Post a Comment