Skip to content

Instantly share code, notes, and snippets.

@AlexSwensen
Last active February 7, 2022 02:12
Show Gist options
  • Save AlexSwensen/725ae0b32873612d2db4 to your computer and use it in GitHub Desktop.
Save AlexSwensen/725ae0b32873612d2db4 to your computer and use it in GitHub Desktop.
$scope.scanCode = function () { // Scan code
$ionicLoading.show({
template: '<ion-spinner></ion-spinner>'
});
console.log("scanCode run");
if ($scope.currentlyScanning === true) {
$ionicLoading.hide();
return;
}
else if (ionic.Platform.platforms.indexOf("browser") !== -1) {
setTimeout(function () {
$ionicLoading.hide();
$cordovaDialogs.alert("QR Code scanner not available in development browser.");
}, 1000);
return;
}
else {
$scope.currentlyScanning = true;
}
$cordovaBarcodeScanner
.scan()
.then(function (barcodeData) {
//$cordovaDialogs.alert(barcodeData.text, 'barcodeData', 'OK');
$ionicLoading.hide();
$scope.currentlyScanning = false;
$scope.launchBrowser(barcodeData.text, '_blank'); // pass data.text (the url in this case) to a function that launches the browser
}, function (error) {
$ionicLoading.hide();
$scope.currentlyScanning = false;
$cordovaDialogs.alert(error, 'barcode Error', 'OK');
});
}; // end scanCode
@robsn
Copy link

robsn commented Aug 17, 2015

Works like a charm! TY

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment