I have a system in place that verifies the existence of a serial number within my database.
If the serial number is found, I want the system to provide me with the corresponding barcode. However, if the serial number does not exist, it should return "false".
Unfortunately, the current implementation of my code is not functioning as expected, most likely due to being nested in an inner function.
I attempted to call another function upon receiving a response, but it seems like this approach is not impacting the scope as intended.
Below is a snippet of my code:
$scope.checkSerial = function(e) {
if (e.which==9) {
res = serialChecker.check($scope.itemsData, $scope.serial, e);
}
}
.service('serialChecker', function($log, $http) {
this.check = function(_itemsData, _serial, e) {
isok = false;
// Fetch serial barcode
config = {
params: { serial: _serial, action: 'check_serial' }
};
$http.get("srvr.php", config)
.then(function(bcresponse) {
$log.info("Currently looking at serial: " + _serial);
barcode = bcresponse.data.barcode;
if (barcode==false) {
return false;
}
angular.forEach(_itemsData, function(value, key){
angular.forEach(value.Items, function(value, key) {
if (value.Codebars == barcode) {
return barcode;
}
});
});
});
}
});
Do you have any suggestions or insights on how to resolve this issue?