AngularJS - Barcode / QRCode scanner
An AngularJS based Barcode / QRCode scanner component.
Table of contents
- Installation
- Usage
- Choosing what decoders to run
- Available format
- Limitations
- Advanced Usage
- Attributes
- Want to Contribute?
- Collection of Components
- Changelog
- Credits
- License
- Keywords
Installation
To install this package, run:
npm i angular-weblineindia-qrcode-scanner --save
or
npm i angular-weblineindia-qrcode-scanner --save
Usage
Import it on your module file:
// some.module.ts; // your very important imports here // the scanner!; // your other nice stuff
Choosing what decoders to run
By default the component comes with QR code decoder enabled, to enable more decoders at once you can simply make use of the formats property like that:
<zxing-scanner [formats]="['QR_CODE', 'EAN_13', 'CODE_128', 'DATA_MATRIX']">
You can also map the formats with the library's enum and pass them from the component:
<zxing-scanner [formats]="allowedFormats">
;
Available format
;
Limitations
The component relies on zxing-typescript which currently supports some 2D and 1D barcode formats, but not all. On iOS-Devices camera access works only in native Safari and not in other Browsers (Chrome,...) or Apps that use an UIWebView or WKWebView. This is not a restriction of this component but of the limited WebRTC support by Apple.
Advanced Usage
You can use some very cool attributes if you want:
<zxing-scanner [enable]="scannerEnabled" [(device)]="desiredDevice" [torch]="torch" (torchCompatible)="onTorchCompatible($event)" (camerasFound)="camerasFoundHandler($event)" (camerasNotFound)="camerasNotFoundHandler($event)" (scanSuccess)="scanSuccessHandler($event)" (scanError)="scanErrorHandler($event)" (scanFailure)="scanFailureHandler($event)" (scanComplete)="scanCompleteHandler($event)"
Logic-side (TypeScript)
// on the template// <zxing-scanner #scanner></zxing-scanner> ;
Preview element's size
To customize CSS, please make use of Angular default piercing methods:
Due to view-encapsulation it is required that the CSS-class that is to be used can be 'seen' from inside the scanner-component.
Attributes :
Attribute | Default | Description |
---|---|---|
enable | true | Starts and Stops the scanning. |
autofocusEnabled | true | Not working at the moment, needs ImageCapture API implementation. |
device | The video-device used for scanning (use one of the devices emitted by camerasFound), it can be set or emit some value. | |
torch experimental | Can turn on/off the device flashlight. | |
torchCompatible experimental | Tells if the device's torch is compatible w/ the scanner. | |
camerasFound | Emits an array of video-devices after view was initialized. | |
camerasNotFound | Emits a void event when cameras aren't found. | |
scanSuccess | Emits the result as string, after a valid QR code was scanned. | |
scanError | Emitted when some error occours during the scan proccess. | |
scanFailure | Emitted when the scanner couldn't decode any relsult from the media stream. | |
scanComplete | Emitted after any scan attempt, no matter what. |
Want to Contribute?
- Created something awesome, made this code better, added some functionality, or whatever (this is the hardest part).
- Fork it.
- Create new branch to contribute your changes.
- Commit all your changes to your branch.
- Submit a pull request.
Collection of Components
We have built many other components and free resources for software development in various programming languages. Kindly click here to view our Free Resources for Software Development.
Changelog
Detailed changes for each release are documented in CHANGELOG.md.
Credits
angular-weblineindia-qrcode-scanner is inspired by @zxing/ngx-scanner.
License
Keywords
angular-qrcode-scanner, angularjs-barcode-scanner, barcode-scanner, qrcode-scanner, angularjs-qrcode, qrcode