angularjs - How to take the result.text from barcodescanner and use as an array -


i trying take result.text returned cordova barcode scanner , parse data string used array, can populate input fields with-in form.

here example code:

document.addeventlistener("deviceready", function() {     $scope.scanmaterial = function() {         $cordovabarcodescanner             .scan()             .then(function(result) {                 var myresult  = result.text;                  alert(myresult);              }, function(error) {                 console.log("an error has happened " + error);             });     }; }, false); 

the barcode data getting: w:966227, i:0253-0050-22, mfg:01/15, b:034, qty:56, n:00034

i end result take string of data , can populate following variables:

var dataobj = {             sessionid: sessionid,             jobid: $stateparams.jobid,             manufacturedate: $scope.manufacturedate,             batchcode: $scope.batchcode,             sku: $scope.sku,             manufactureorigin: 'unknown',             createdclient: $scope.createdclient,             latitude: $scope.lat,             longitude: $scope.long,             product: { id : 1}         };          cfploadingbar.start();             $http.post(baseurl + 'material/postnewmaterial', dataobj)                 .success(function() {                     alertsmanager.addalert('success: have added material.', 'alert-success');                     cfploadingbar.complete();                     $scope.materialcollapsed = true;                 }).error(function(dataobj) {                     alertsmanager.addalert('failure meesage: ' + json.stringify({dataobj:dataobj}), 'alert-danger');                     cfploadingbar.complete();                 });                 $timeout(function(){                     alertsmanager.clearalerts();                 }, 5000);     }; 

this gives desired results, , splits result.text usable format, can sent api server.

document.addeventlistener("deviceready", function() {     $scope.scanmaterial = function() {           $cordovabarcodescanner             .scan()             .then(function(result) {                  var codearray = result.text.split(',');                 $scope.sku = codearray[1].replace("i:", "").trim();                 $scope.controlno = codearray[0].replace("w:", "").trim();                 $scope.manufacturedate = codearray[2].replace("mfg:", "").trim();                 $scope.batchcode = codearray[3].replace("b:", "").trim();                  var dataobj = {                     sessionid: sessionid,                     jobid: $stateparams.jobid,                     manufacturedate: $scope.manufacturedate,                     batchcode: $scope.batchcode,                     sku: $scope.sku,                     manufactureorigin: 'unknown',                     createdclient: new date(),                     latitude: $scope.lat,                     longitude: $scope.long,                     product: { id : 1}                 };                  $http.post(baseurl + 'material/postnewmaterial', dataobj)                     .success(function() {                         alertsmanager.addalert('success: have added material.', 'alert-success');                         $state.go('^');                     }).error(function(dataobj) {                         alertsmanager.addalert('failure meesage: ' + json.stringify({dataobj:dataobj}), 'alert-danger');                     });                     $timeout(function(){                         alertsmanager.clearalerts();                     }, 5000);              }, function(error) {                 console.log("an error has happened " + error);             });     }; }, false); 

Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -