Hi.
I have a mega simple app using a bar code scanner, after trying the Cordova one I decided to look at the Scandit SDK - the scanner works fine but I have having such a weird time updating on simple part of the DOM with code that worked perfectly with the Cordova scanner.
I have placed the code below in case anyone can see an obvious gotcha, the only grain of hope I can find is that I tried using $scope.apply() to force an update which provides a eval error suggesting that the $scope var is not in the scope of the funtion - but for the life of me I cant see how not.
Snippet from the template html:
<div class="item item-text-wrap">
<span ng-bind-html="scan_result">No data, please scan a ticket</span>
</div>
Then in the controller:
.controller('scanBarCode', function($scope, $state) {
//sets the html span text
$scope.scan_result = "No data, please scan a ticket";
//set up a var for the scanned
var scanned;
function success(resultArray) {
scanned = resultArray[0];
scanned = JSON.parse(scanned);
var scantext = "<strong>Booking Ref : "+scanned.id+"</strong><br/>";
scantext += "Adults : "+scanned.adults+"<br>";
scantext += "Children : "+scanned.child+"<br>";
scantext += "Concessions : "+scanned.cons+"<br>";
scantext += "Family Ticket : "+scanned.family+"<br>";
//console.log(scantext);
$scope.scan_result = scantext;
};
function failure(error) {
alert("Failed: " + error);
};
$scope.scanBarcode = function() {
// See below for all available options.
cordova.exec(success, failure, "ScanditSDK", "scan",
["appKeywasinHere",
{"beep": true,
"1DScanning" : false,
"2DScanning" : true}]);
};
})
The very odd thing is that the console.log command shows the scanned text perfectly in the console - yet the following line will not update the DOM. I have tried sending the scanned text to a function in the same controller but somehow it simply loses the ability to communicate with the template.
I’ve tried the $scope.$watch() but that ran once and then did not run again - its almost like the text is being run in a completely seperate instance - any ideas please?
Oh I should add - when the scan button which kicks this off is clicked again, the text then appears in the span - so it is being stored (I think) just not displayed until Angular comes around agin, or at least thats what I think - probably a curved ball.
Thanks in advance!