Skip to content

Angular

Implementation of the Qr grid library for Angular applications.

Installation

sh
npm install @qrgrid/angular
sh
bun add @qrgrid/angular
sh
pnpm install @qrgrid/angular
sh
yarn add @qrgrid/angular

Using Canvas

typescript
import { CanvasQr } from "@qrgrid/angular";

<qr input="Hello World!"/>

Props and Events

PropTypeDescriptionDefault
inputstringData to encode
qrOptions?QrOptionsOptions for QR encoding
image?QrImageOptionImage options for the image in QR codesizePercent: 15, opacity: 1, overlap: true, border: false
size?numberCanvas size400
bgColor?QrColor | ((ctx: CanvasRenderingContext2D) => QrColor)Background colorblack
color?QrColor | ((ctx: CanvasRenderingContext2D) => QrColor)QR code colorwhite
moduleStyle?ModuleStyleFunctionCustom styles for QR modules
EventsEvent TypeDescriptionDefault
onQrDataEncoded?(qr: QR) => void;Emitted once sata is encoded
onQrRendered?(ctx: CanvasRenderingContext2D, size: number, qr: QR) => void;Emitted once QR code is generated

see in code.

Using Svg

typescript
import { SvgQr } from "@qrgrid/angular";

<qr input="Hello World!"/>

Props

PropTypeDescriptionDefault
inputstringData to encode
qrOptions?QrOptionsQr Options for QR encoding
image?QrImageOptionImage options for image in the QR codesizePercent: 15, opacity: 1, overlap: true, border: false
size?numberSVG size400
bgColor?stringBackground colorblack
color?string | { codeword?: string; finder?: string }QR code colorwhite
moduleStyle?ModuleStyleFunctionCustom styles for QR modules
EventsEvent TypeDescriptionDefault
onQrDataEncoded?(qr: QR) => void;Emitted once sata is encoded
onQrRendered?(ctx: CanvasRenderingContext2D, size: number, qr: QR) => void;Emitted once QR code is generated

see in code.

Examples

Explore Styles for custom styling and other utilities

  • Basic

    typescript
    <qr input="Hello World!" />
  • ErrorCorrection

    typescript
    <qr input="Hello World!" [qrOptions]="{errorCorrection: 'H'}" />
  • Color

    typescript
    <qr input="Hello World!" bgColor="#F8EDED" color="#173B45" />
  • Module Style from @qrgrid/styles

    typescript
    import { dotModuleStyle } from "@qrgrid/styles/canvas/styles";
    
    <qr input="Hello World!" [moduleStyle]={dotModuleStyle} />
    typescript
    import { smoothModuleStyle } from "@qrgrid/styles/canvas/styles";
    
    <qr input="Hello World!" [moduleStyle]={smoothModuleStyle} />
  • Images

    typescript
    <qr input="Hello World!" [image]="{ src: ''./vite.svg' }" />
    typescript
    <qr input="Hello World!" [image]="{ src: './vite.svg', overlap: false }" />
  • Downloading using @qrgrid/styles

    typescript
    import { CanvasQr } from "@qrgrid/angular";
    import { downloadQr } from "@qrgrid/styles/canvas/utils";
    
    // inside class component
    @ViewChild(CanvasQr) canvasQr!: CanvasQr;
    
    download() {
      if (this.canvasQr?.canvas?.nativeElement) {
        downloadQr(this.canvasQr.canvas.nativeElement);
      }
    }
    typescript
    import { SvgQr } from "@qrgrid/angular";
    import { downloadQr} from "@qrgrid/styles/svg/utils";
    
    // inside class component
    @ViewChild(SvgQr) svgQr!: SvgQr;
    
    download() {
      if (this.svgQr?.svg?.nativeElement) {
        downloadQr(this.svgQr.svg.nativeElement);
      }
    }

For more examples and customization options, see the examples.

Released under the MIT License.