I'm using quagga plugin form barcode scanner.
I want to call searchbybarcode (barcode){}
function inside Quagga.onDetected
when I have e result.
Quagga.onDetected((res) => {
console.log('barcode', res.codeResult.code)
this.searchbybarcode(res.codeResult.code)
});
When I call this function show
error core.js:6014 ERROR TypeError: Cannot read property 'searchbybarcode' of undefined
searchbybarcode(barcode) {
console.log('mybarcode', barcode)
this.dataservice.GetByBarCode(barcode).then(models => {
this.PersonDetailsByBarcode = models;
})
}
Update
scanbarcode() {
if (!navigator.mediaDevices || !(typeof navigator.mediaDevices.getUserMedia === 'function')) {
this.errorMessage = 'getUserMedia is not supported';
return;
}
Quagga.init({
inputStream: {
name: "Live",
type: "LiveStream",
constraints: {
width: 480,
height: 320,
facingMode: "environment"
},
},
decoder: {
readers: [
"code_128_reader",
"ean_reader",
"ean_8_reader",
"code_39_reader",
"code_39_vin_reader",
"codabar_reader",
"upc_reader",
"upc_e_reader",
"i2of5_reader"
],
}
}, function (err) {
if (err) {
console.log(err);
return
}
console.log("Initialization finished. Ready to start");
Quagga.start();
Quagga.onProcessed(function (result) {
var drawingCtx = Quagga.canvas.ctx.overlay,
drawingCanvas = Quagga.canvas.dom.overlay;
if (result) {
if (result.boxes) {
drawingCtx.clearRect(0, 0, parseInt(drawingCanvas.getAttribute("width")), parseInt(drawingCanvas.getAttribute("height")));
result.boxes.filter(function (box) {
return box !== result.box;
}).forEach(function (box) {
Quagga.ImageDebug.drawPath(box, { x: 0, y: 1 }, drawingCtx, { color: "green", lineWidth: 2 });
});
}
if (result.box) {
Quagga.ImageDebug.drawPath(result.box, { x: 0, y: 1 }, drawingCtx, { color: "#00F", lineWidth: 2 });
}
if (result.codeResult && result.codeResult.code) {
Quagga.ImageDebug.drawPath(result.line, { x: 'x', y: 'y' }, drawingCtx, { color: 'red', lineWidth: 3 });
Quagga.onDetected((res) => {
console.log('barcode', res.codeResult.code)
});
}
}
});
});
}
Please, can you share with me any idea how to call a function inside Quagga.onDetected