Angular HTML5 QR Code Library

December 7, 2024 ยท View on GitHub

The Angular HTML5 QR Code Library based on html5-qrcode library The Angular HTML5 QR Code Library provides an Angular wrapper for the html5-qrcode library, allowing developers to easily integrate QR code and barcode scanning functionalities into their Angular applications.

Component Template Usage

npm install angular-html5-qrcode
import { AngularHtmlQrcodeComponent } from 'angular-html5-qrcode';
<angular-html-qrcode
  [types]="[Html5QrcodeSupportedFormats.QR_CODE]"
  [fps]="2"
  [aspectRatio]="1.333334"
  [disableFlip]="false"
  [supportCameraOrFile]="'camera'"
  (onSuccess)="handleScanSuccess($event)"
  (onError)="handleScanError($event)">
</angular-html-qrcode>

Input Properties Table

PropertyTypeDefaultDescription
typesHtml5QrcodeSupportedFormats[]All supported formatsList of formats to support during scanning.
fpsnumber10Frames per second for the camera feed.
selectorIDstring'reader'ID of the container element for the scanner.
rememberLastUsedCamerabooleantrueWhether to remember the last used camera.
aspectRationumber1.333334Aspect ratio of the camera feed.
disableFlipbooleanfalseDisable the flipping of the camera feed (useful for mirrored scans).
supportCameraOrFilestring'both'Choose whether to enable camera scanning, file scanning, or both.
qrboxQrDimensions , QrDimensionFunction{ width: 250, height: 250 }Dimensions of the scanning box.

Output Events Table

EventPayload TypeDescription
onSuccessQrcodeSuccessCallbackTriggered when a QR code or barcode is successfully scanned.
onErrorQrErrorCallbackTriggered when there is an error during scanning.

Import the Service

import { Component } from '@angular/core';
import { AngularHtmlQrcodeService } from 'angular-html5-qrcode';

export class AppComponent {
  constructor(private qrCodeService: AngularHtmlQrcodeService) {}
}

Methods

MethodDescriptionParametersReturns
clear()Clears the scanner instance and releases resources.NonePromise<void> or undefined.
pause(shouldPauseVideo)Temporarily pauses the scanner.- shouldPauseVideo (boolean): Whether to pause video input (default: true).void.
resume()Resumes the scanner if it was paused.Nonevoid.