@qrcodesdk/angular
Angular components that render QR codes as inline SVG, as PNG, WebP, GIF, or JPEG Image elements, or as Canvas elements.
Install
Section titled “Install”npm install @qrcodesdk/angularpnpm add @qrcodesdk/angularvp add @qrcodesdk/angulardeno add npm:@qrcodesdk/angularbun add @qrcodesdk/angularyarn add @qrcodesdk/angularQuick start
Section titled “Quick start”Import a component and add it to your component’s imports:
import {Component} from '@angular/core';
import {QRCodeSVG, type QRCodeSVGOptions} from '@qrcodesdk/angular';
@Component({ selector: 'app-root', imports: [QRCodeSVG], template: ` <figure> <qrcode-svg [options]="options" payload="https://qrcodesdk.dev" /> <figcaption> Scan the code or open <a href="https://qrcodesdk.dev">qrcodesdk.dev</a> </figcaption> </figure> `,})export class App { protected readonly options: QRCodeSVGOptions = { accessibility: {ariaLabel: 'Scan to open qrcodesdk.dev'}, };}ariaLabelnames the QR code for screen readers. The link gives everyone another way to reach the destination.- Without
accessibilityoptions, the QR code is decorative and hidden from assistive technology. Leave it unlabeled only when nearby content, such as this link, already explains it. QRCodePNG,QRCodeWebP,QRCodeGIF,QRCodeJPEG, andQRCodeCanvastake the samepayloadandoptionsinputs. Image components also acceptaccessibility.alt.
Version compatibility
Section titled “Version compatibility”| @qrcodesdk/angular | Angular |
|---|---|
0.x.x |
^20.0.0 ^21.0.0 ^22.0.0 |
Components
Section titled “Components”Each output format has its own standalone component. Your bundle only includes the encoders of the components you import.
| Component | Selector | Output | Download support |
|---|---|---|---|
QRCodeSVG | qrcode-svg | Inline SVG element | SVG |
QRCodePNG | qrcode-png | PNG-backed <img> | PNG |
QRCodeWebP | qrcode-webp | WebP-backed <img> | WebP |
QRCodeGIF | qrcode-gif | GIF-backed <img> | GIF |
QRCodeJPEG | qrcode-jpeg | JPEG-backed <img> | JPEG |
QRCodeCanvas | qrcode-canvas | <canvas> element | None |
Component props
| Prop | Type | Description |
|---|---|---|
payload input | string | number | Required QR code payload. |
options input | Component-specific options | Optional matrix options and renderer options, such as QRCodeSVGOptions for QRCodeSVG. |
class, style, other host attributes | Host element attributes | Apply to the <qrcode-*> host element. There is no wrapper <div>. The output element is a direct child of the host, which is inline by default. |
Template reference variable or viewChild() | Component instance | Every component except QRCodeCanvas implements QRCodeDownloadHandle and has download(filename?). |
Unlike the React, Vue, and Svelte components, the Angular components render no wrapper <div>. Set
display: block on the host element, such as <qrcode-svg>, to size the QR code with CSS.
Choose an image format
Section titled “Choose an image format”QRCodePNGuses the browser’s native PNG encoder.QRCodeWebPuses a lossless encoder bundled in the SDK. It also works in Safari and usually produces the smallest file.QRCodeGIFis limited to 256 colors and on-or-off transparency. Prefer PNG or WebP for transparent backgrounds and photographic center images.QRCodeJPEGis lossy and has no transparency. It blends transparent pixels onto a white matte by default. Itsqualityoption ranges from 1 to 100 and defaults to 92. Use it only when a destination requires JPEG.
See Image element renderers for details.
Live examples
Section titled “Live examples”SVG component
Section titled “SVG component”import {Component} from '@angular/core';
import {QRCodeSVG} from '@qrcodesdk/angular';
@Component({ selector: 'qrcode-angular-svg-example', imports: [QRCodeSVG], template: ` <qrcode-svg [options]="{ accessibility: { title: 'QR code for qrcodesdk.dev', ariaLabel: 'Scan to open qrcodesdk.dev', }, }" payload="https://qrcodesdk.dev" /> `,})export class QRCodeSVGExample {}PNG component
Section titled “PNG component”import {Component} from '@angular/core';
import {QRCodePNG, type QRCodePNGImageOptions} from '@qrcodesdk/angular';
@Component({ selector: 'qrcode-angular-png-example', imports: [QRCodePNG], template: ` <qrcode-png [options]="options" payload="https://qrcodesdk.dev" /> `,})export class QRCodePNGExample { protected readonly options: QRCodePNGImageOptions = { style: {moduleSize: 8, quietZone: 4}, accessibility: { alt: 'QR code: scan to open qrcodesdk.dev', }, };}WebP component
Section titled “WebP component”import {Component} from '@angular/core';
import {QRCodeWebP, type QRCodeWebPImageOptions} from '@qrcodesdk/angular';
@Component({ selector: 'qrcode-angular-webp-example', imports: [QRCodeWebP], template: ` <qrcode-webp [options]="options" payload="https://qrcodesdk.dev" /> `,})export class QRCodeWebPExample { protected readonly options: QRCodeWebPImageOptions = { style: {moduleSize: 8, quietZone: 4}, accessibility: { alt: 'QR code: scan to open qrcodesdk.dev', }, };}GIF component
Section titled “GIF component”import {Component} from '@angular/core';
import {QRCodeGIF, type QRCodeGIFImageOptions} from '@qrcodesdk/angular';
@Component({ selector: 'qrcode-angular-gif-example', imports: [QRCodeGIF], template: ` <qrcode-gif [options]="options" payload="https://qrcodesdk.dev" /> `,})export class QRCodeGIFExample { protected readonly options: QRCodeGIFImageOptions = { style: {moduleSize: 8, quietZone: 4}, accessibility: { alt: 'QR code: scan to open qrcodesdk.dev', }, };}JPEG component
Section titled “JPEG component”import {Component} from '@angular/core';
import {QRCodeJPEG, type QRCodeJPEGImageOptions} from '@qrcodesdk/angular';
@Component({ selector: 'qrcode-angular-jpeg-example', imports: [QRCodeJPEG], template: ` <qrcode-jpeg [options]="options" payload="https://qrcodesdk.dev" /> `,})export class QRCodeJPEGExample { protected readonly options: QRCodeJPEGImageOptions = { style: {moduleSize: 8, quietZone: 4}, quality: 90, accessibility: { alt: 'QR code: scan to open qrcodesdk.dev', }, };}Canvas component
Section titled “Canvas component”import {Component} from '@angular/core';
import {QRCodeCanvas, type QRCodeCanvasOptions} from '@qrcodesdk/angular';
@Component({ selector: 'qrcode-angular-canvas-example', imports: [QRCodeCanvas], template: ` <qrcode-canvas [options]="options" payload="https://qrcodesdk.dev" /> `,})export class QRCodeCanvasExample { protected readonly options: QRCodeCanvasOptions = { style: { moduleSize: 8, quietZone: 4, foreground: '#111827', background: '#ffffff', }, accessibility: {ariaLabel: 'Scan to open qrcodesdk.dev'}, };}PNG download
Section titled “PNG download”import {Component} from '@angular/core';
import {QRCodePNG} from '@qrcodesdk/angular';
@Component({ selector: 'qrcode-angular-download-png-example', imports: [QRCodePNG], template: ` <qrcode-png #qrcode [options]="{ accessibility: {alt: 'QR code: scan to open qrcodesdk.dev'}, }" payload="https://qrcodesdk.dev" /> <button (click)="qrcode.download('qrcodesdk')" type="button">Download PNG</button> `,})export class QRCodeDownloadPNGExample {}Center images
Section titled “Center images”For PNG, WebP, GIF, JPEG, and Canvas components:
- Load and decode a browser image.
- Store the options with
centerImage: canvasCenterImage(image)in a signal. - Render the component inside an
@ifblock once the signal has a value.
QRCodeSVG takes svgCenterImage() with an embedded data URL instead. See
Add a center image for the complete component and template.
Download files
Section titled “Download files”Every component except QRCodeCanvas exposes download(filename?). Get it through a template
reference variable or viewChild(). The method appends the file extension when needed.
See Download or save for a complete Angular example. For manual downloads, see Export a canvas manually.
Server-side rendering
Section titled “Server-side rendering”QRCodeSVGproduces runtime-neutral SVG and renders on the server.QRCodePNG,QRCodeWebP,QRCodeGIF,QRCodeJPEG, andQRCodeCanvasneed browser DOM and Canvas APIs. On the server, they render an empty host element and skip downloads. They fill the host after hydration.
Shared options
Section titled “Shared options”The options input groups encoding settings under matrix. Renderer settings, such as style,
accessibility, and centerImage, sit next to it:
import {type QRCodeSVGOptions, circle, finder, rounded} from '@qrcodesdk/angular';
const options: QRCodeSVGOptions = { matrix: {errorCorrectionLevel: 'H'}, style: {moduleSize: 8, quietZone: 4, modules: rounded(), finder: finder({center: circle()})}, accessibility: {ariaLabel: 'Scan to open qrcodesdk.dev'},};Each component has its own options type:
| Component | Options type | Extra options |
|---|---|---|
QRCodeSVG |
QRCodeSVGOptions |
None |
QRCodePNG |
QRCodePNGImageOptions |
None |
QRCodeWebP |
QRCodeWebPImageOptions |
None |
QRCodeGIF |
QRCodeGIFImageOptions |
transparency.threshold |
QRCodeJPEG |
QRCodeJPEGImageOptions |
quality, transparency.matte |
QRCodeCanvas |
QRCodeCanvasOptions |
None |
Learn more about each group:
- Builder and matrix covers the fields inside
matrix. - Customize appearance covers
style. - Renderer outputs covers output-specific options.
Import payload helpers, such as wifiPayload(), from @qrcodesdk/angular.
QRCodeError comes from @qrcodesdk/core. To use it,
add Core to the project.
Mixed-mode segmentation
Section titled “Mixed-mode segmentation”Mixed-mode segmentation is opt-in. Import automaticSegmenter from @qrcodesdk/angular and pass it
as matrix.segmenter:
import {type QRCodeSVGOptions, automaticSegmenter} from '@qrcodesdk/angular';
const options: QRCodeSVGOptions = {matrix: {mode: 'auto', segmenter: automaticSegmenter}};Keep options stable
Section titled “Keep options stable”options is a signal input compared by identity.
- Replacing the bound object renders the QR code again.
- Changing a property of the same object does not.
Create a new object instead, for example with signal.set(), signal.update(), or computed().
Object literals in a template are fine: Angular caches them and recreates them only when a value
bound inside them changes.
Errors
Section titled “Errors”Components throw QRCodeError for invalid payloads and options. They render in effect(), so
Angular reports these errors to its ErrorHandler.
Wrap downloads called from an event handler in your own try/catch. See
Check errors from framework packages.
Public API
Section titled “Public API”import { type QRCodeAlignmentCenterShape, type QRCodeAlignmentOptions, type QRCodeAlignmentRingShape, type QRCodeAlignmentStyle, QRCodeCanvas, type QRCodeCanvasAccessibilityOptions, type QRCodeCanvasCenterImage, type QRCodeCanvasOptions, type QRCodeCenterImageLayout, type QRCodeCircleShapeOptions, type QRCodeColor, type QRCodeDataImageURL, type QRCodeDownloadHandle, type QRCodeEncodingMode, type QRCodeErrorCorrectionLevel, type QRCodeFinderCenterShape, type QRCodeFinderOptions, type QRCodeFinderRingShape, type QRCodeFinderStyle, QRCodeGIF, type QRCodeGIFImageOptions, type QRCodeImageAccessibilityOptions, QRCodeJPEG, type QRCodeJPEGImageOptions, type QRCodeKanji, type QRCodeMask, type QRCodeMatrixOptions, type QRCodeMode, type QRCodeModulePattern, type QRCodeModuleShape, QRCodePNG, type QRCodePNGImageOptions, type QRCodePayload, type QRCodeRoundedShapeOptions, QRCodeSVG, type QRCodeSVGAccessibilityOptions, type QRCodeSVGCenterImage, type QRCodeSVGOptions, type QRCodeSegment, type QRCodeSegmenter, type QRCodeSegmenterOptions, type QRCodeShape, type QRCodeShapePath, type QRCodeShapePiece, type QRCodeVersion, type QRCodeVisualStyle, QRCodeWebP, type QRCodeWebPImageOptions, alignment, automaticSegmenter, canvasCenterImage, circle, customShape, diagonal, finder, kanji, rounded, svgCenterImage,} from '@qrcodesdk/angular';@qrcodesdk/angular
- Version
- v0.0.6
- Downloads
- 788/mo
- Install size
- 904.4 kB
- Bundled size
- 36.2 kB
Related pages
Section titled “Related pages”Support QRCodeSDK
If you find QRCodeSDK useful, please consider sponsoring the project!