Created
August 1, 2019 13:30
-
-
Save mdshadman/6dc05816cc8dac583f86a78dea190637 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component } from '@angular/core'; | |
import { BarcodeScanner, BarcodeScannerOptions } from '@ionic-native/barcode-scanner/ngx'; | |
@Component({ | |
selector: 'app-home', | |
templateUrl: 'home.page.html', | |
styleUrls: ['home.page.scss'], | |
}) | |
export class HomePage { | |
scannedData: any; | |
encodedData: ''; | |
encodeData: any; | |
constructor(public barcodeCtrl: BarcodeScanner) { } | |
goToBarcodeScan() { | |
const options: BarcodeScannerOptions = { | |
preferFrontCamera: true, | |
showFlipCameraButton: true, | |
showTorchButton: true, | |
torchOn: false, | |
prompt: 'Place a barcode inside the scan area', | |
resultDisplayDuration: 500, | |
formats: 'QR_CODE,PDF_417 ', | |
orientation: 'landscape', | |
}; | |
this.barcodeCtrl.scan(options).then(barcodeData => { | |
console.log('Barcode data', barcodeData); | |
this.scannedData = barcodeData; | |
}).catch(err => { | |
console.log('Error', err); | |
}); | |
} | |
goToCreateCode() { | |
this.barcodeCtrl.encode(this.barcodeCtrl.Encode.TEXT_TYPE, this.encodeData).then((encodedData) => { | |
console.log(encodedData); | |
this.encodedData = encodedData; | |
}, (err) => { | |
console.log('Error occured : ' + err); | |
}); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment