$scope.scanBarcode = function() {
$cordovaBarcodeScanner.scan().then(function(imageData) {
alert(imageData.text);
//Simple inject the var in the $scope var
$scope.code = imageData.text; //where "code" is the value from ng-model (basic data-binding)
console.log("Barcode Format -> " + imageData.format);
console.log("Cancelled -> " + imageData.cancelled);
}, function(error) {
console.log("An error happened -> " + error);
});
};
This stackoverflow thread has some excellent advice and reasoning why direct manipulation like this can cause issues later on (I appreciate you’re not using jQuery here, but the principle is the same)
it really is worth getting used to referencing a separate model rather than directly peeking at the DOM - it can cause all sorts of hard-to-debug side-effects later on.
Can you help me with something similar since i’m rather new.
I want to spare the user the trouble of filling the address if he decide to share his location for the delivery and therefore this is a GPS Coordinates function to fill 3 fields (long/lat and a combined field)
// CAPTURE ADDRESS GPS LONG/LAT******************
function getLocationConstant() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(onGeoSuccess, onGeoError);
} else {
alert(“Sorry, We couldn’t get your Geolocation, Please fill the address manually”);
}
}
// If we have a successful location update
function onGeoSuccess(event) {
document.getElementById(“Latitude”).value = event.coords.latitude;
document.getElementById(“Longitude”).value = event.coords.longitude;
document.getElementById(“Position1”).value = event.coords.latitude + ", " + event.coords.longitude;
}
// **************** MY FORM **********************************