Issue
In Ionic app, I use Barcode Scanner but after scanning it returns: [object Object]
Here is my code:
import { Component } from '@angular/core';
import {BarcodeScanner} from '@ionic-native/barcode-scanner/ngx';
@Component({
selector: 'app-home',
templateUrl: 'home.page.html',
styleUrls: ['home.page.scss'],
})
export class HomePage {
scannedCode="dd";
constructor(private barcodeScanner:BarcodeScanner) {}
scanCode(){
this.barcodeScanner.scan().then(barcodeData=>{
this.scannedCode=barcodeData;
})
}
}
Solution
The return type is actually an object. You must get the text encoded value in text property:
scanCode()
{
this.barcodeScanner.scan().then(
barcodeData => {
this.scannedCode=barcodeData.text;
}
)
}
Next time when you get [object Object]
from some variable, try console loggin it to see ot contents.
console.log(barcodeData);
Answered By - Elias Soares
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.