ngx-qr
TypeScript icon, indicating that this package has built-in type declarations

1.1.13 • Public • Published

ngx-qr

QrScanner will scan for a QRCode from your Web-cam and return its string.

usage

$ npm install --save ngx-qr
// app.module.ts
import { NgQrScannerModule } from 'ngx-qr';
@NgModule({
  // ...
  imports: [
    // ...
    NgQrScannerModule,
  ],
  // ...
})
export class AppModule { }
<!-- app.component.html -->
<qr-scanner (capturedQr)="capturedQr($event)"></qr-scanner>
 
// app.component.ts
import { Component, OnInit, AfterViewInit } from '@angular/core';
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
    styleUrls: ['./app.component.scss'],
})
export class AppComponent implements OnInit, AfterViewInit {
 
    ngOnInit() {
    }
 
    capturedQr(result: string) {
        console.log(result);
    }
 
    ngAfterViewInit() {
    }
}
 

Translation

Provide the following texts:

export interface QrScannerTexts {
  NotSupportedHTML: string;
  DeviceDefaultPrefix: string;
  StopCameraText: string;
  OpenButtonText: string;
}
<!-- app.component.html -->
<qr-scanner 
    (capturedQr)="capturedQr($event)"
    [texts]="{
        NotSupportedHTML: `You are using an <strong>outdated</strong> browser.`,
        DeviceDefaultPrefix: `Camera`,
        StopCameraText: `Stop Camera`,
        OpenButtonText: `Open QR Code File...` }">
</qr-scanner>
 

Styling

Button styles can be changed:

<!-- app.component.html -->
<qr-scanner 
    (capturedQr)="capturedQr($event)"
    [buttonClass]="'ngClassForButtons'">
</qr-scanner>
 

Upload QR Feature

You can let users upload a QR code using:

<!-- app.component.html -->
<qr-scanner 
    (capturedQr)="capturedQr($event)"
    [allowUpload]="true">
</qr-scanner>
 

If you only need upload QR feature, you can use the following:

<!-- app.component.html -->
<qr-scanner 
    (capturedQr)="capturedQr($event)"
    [allowUpload]="true"
    [disableScan]="true">
</qr-scanner>
 

Error handling

Errors are shown on the error output:

<!-- app.component.html -->
<qr-scanner 
    (error)="onError($event)"
    (capturedQr)="capturedQr($event)">
</qr-scanner>
 

Package Sidebar

Install

npm i ngx-qr

Weekly Downloads

33

Version

1.1.13

License

GPL-3.0-or-later

Unpacked Size

2.66 MB

Total Files

78

Last publish

Collaborators

  • armanfatahi