I am not too familiar with angularJS and am having trouble trying to use http.get(). I am completing a QR scan and the text that is received from the QR code will then be placed into my url. The problem that I am receiving is that the http.get() is executing before the scan is being completed. Therefore returning "Error". How can I make this so that the http.get(url) is executed only after the $scope.QRScan() function is completed.
$scope.QRscan(); /// Want to finish first
var params = "?number=" + $scope.QRText;
params += "&action=ci";
var url = "http://test/test.php" + params;
var promise = $http.get(url);
promise.then(
function(payload) {
var r = payload.data;
if (r.status.toString() == '1') {
var alertPopup = $ionicPopup.alert({
title: ' successful ',
});
} else {
var alertPopup = $ionicPopup.alert({
title: 'Error',
});
};
});
QRScan()
$scope.QRscan = function () {
$cordovaBarcodeScanner.scan().then(function (qrData) {
}, function (error) {
var alertPopup = $ionicPopup.alert({
title: 'There was an error scanning the QR code.',
});
});
$scope.QRText = qrData.text;
};