I've encountered an issue with my barcode scan detection code. Originally, the code was working fine when it was placed directly in an AngularJS controller. However, I needed to use the same code in another controller as well, so I moved the scan code into a separate JS file that both controllers could access. After including both files in the HTML page, I expected everything to work smoothly. But now, when the scan code detects a barcode scan and tries to call a method on the other controller, I keep getting this error:
0x800a1391 - JavaScript runtime error: 'onBarcodeScan' is undefined
The problematic section in barcodeScan.js looks like this:
setTimeout(function () {
if (chars.length == 12) {
var barcode = chars.join("");
onBarcodeScan(barcode); // This is where the error occurs
}
chars = [];
pressed = false;
}, 500);
In my AngularJS controller, the function definition for onBarcodeScan is as follows:
var onBarcodeScan = function (barcode) {
$scope.$apply(function () {
$scope.state.userEnteredSubId = barcode;
$scope.onSubmitSubId();
});
}
I can't seem to figure out what I'm missing. It's worth noting that the order of script inclusion in the index HTML page is correct:
<script src="js/cassetteController.js"></script>
<script src="js/barcodeScan.js"></script>