How to implement QR Code Scanner in ionic2?
Suggestion:
How about googling for âIonic QR Scannerâ and looking at the #1 result?
i installed plugin but i get blank screen
what should i write in html to see qr scanner?
Hi, @cooldp007
if you getting any error you can put screen short and add this code in html
<ion-content padding>
<button ion-button (click)="scan()">Scan ... </button>
</ion-content>
Thanks,
Hello, @addwebsolution
my page.component.ts file:-
ionViewDidLoad()
{
console.log(âionViewDidLoad ScanCodePageâ);
this.qrScanner.prepare()
.then((status: QRScannerStatus) =>
{
if(status.authorized)
{
let scanSub = this.qrScanner.scan().subscribe((text: string) =>
{
this.qrScanner.hide();
scanSub.unsubscribe();
});
this.qrScanner.show();
}
else if (status.denied)
{
}
else
{
}
})
.catch((e: any) => console.log(âError isâ, e));
}
}
I got this error
cordova_not_available
co.scan is not a function
so where should i write scan function and what content i write inside scan function?
In the page controller. Incidentally, I would recommend using the ZBar plugin here instead. There are a bunch of threads here detailing much difficulty getting that QRScanner plugin to work properly for people.
Hello, @rapropos
My scan-code.ts File:-
import { Component } from â@angular/coreâ;
import { IonicPage, NavController, NavParams } from âionic-angularâ;
import { QRScanner, QRScannerStatus } from â@ionic-native/qr-scannerâ;
import { ZBar, ZBarOptions } from â@ionic-native/zbarâ;
@IonicPage()
@Component({
selector: âpage-scan-codeâ,
templateUrl: âscan-code.htmlâ,
})
export class ScanCodePage
{
constructor(public navCtrl: NavController, public navParams: NavParams,private qrScanner: QRScanner,private zbar: ZBar)
{
}
ionViewDidLoad()
{
console.log(âionViewDidLoad ScanCodePageâ);
let options: ZBarOptions =
{
flash: 'off',
drawSight: false
};
this.zbar.scan(options)
.then(result =>
{
console.log(result); // Scanned code
})
.catch(error =>
{
console.log(error); // Error message
});
}
}
Now nothing displayed in my screen
so what should i do for it?