У меня проблема с плагином QR Scanner Ionic (я пробовал много версий) Проблема в том, что сканер возвращает значение предыдущего сканирования, и, конечно, первое сканирование пустое.
import { Component } from '@angular/core';
import { QRScanner, QRScannerStatus } from '@ionic-native/qr-scanner';
@Component({
selector: 'app-tab1',
templateUrl: 'tab1.page.html',
styleUrls: ['tab1.page.scss']
})
export class Tab1Page {
constructor() {
this.ionApp.style.display = 'block';
}
public error="Sample";
public counter = 0;
public ionApp = <HTMLElement>document.getElementsByTagName('ion-app')[0];
public data= "";
public startScanner(){
QRScanner.prepare()
.then((status: QRScannerStatus) => {
if (status.authorized) {
this.ionApp.style.display = ' none';
// camera permission was granted
QRScanner.show();
// start scanning
let scanSub = QRScanner.scan().subscribe((text: string) => {
console.log('Scanned something', text);
this.data = text;
QRScanner.hide(); // hide camera preview
scanSub.unsubscribe(); // stop scanning
this.ionApp.style.display = 'block';
});
} else if (status.denied) {
// camera permission was permanently denied
// you must use QRScanner.openSettings() method to guide the user to the settings page
// then they can grant the permission from there
} else {
// permission was denied, but not permanently. You can ask for permission again at a later time.
}
})
.catch((e: any) =>this.error = e);
}
}