Skip to content

Instantly share code, notes, and snippets.

@Dominent
Created January 13, 2020 07:38
Show Gist options
  • Save Dominent/7094885dd5e4ddbf9e277fcfc392d83f to your computer and use it in GitHub Desktop.
Save Dominent/7094885dd5e4ddbf9e277fcfc392d83f to your computer and use it in GitHub Desktop.
/* tslint:disable */
import { Component, Input, ElementRef, OnInit } from '@angular/core';
import { CorrectLevel, QRCodeConstructor } from './qrcode.interface';
import * as __QRCode from 'davidshimjs-qrcodejs';
const QRCode: QRCodeConstructor = __QRCode;
@Component({
selector: 'tide-qrcode',
template: '',
styles: [':host { display: flex; border: 5px solid; }']
})
export class QrCodeComponent implements OnInit {
@Input() text: string;
@Input() width: number;
@Input() height: number;
@Input() colorDark: string = '#ffffff';
@Input() colorLight: string = '#000000';
constructor(
private _element: ElementRef
) {}
ngOnInit(): void {
try {
new QRCode(this._element.nativeElement, {
text: this.text,
width: this.width,
height: this.height,
colorDark: this.colorDark,
colorLight: this.colorLight,
correctLevel: CorrectLevel.H
});
} catch (error) {
console.error(`Error generating QR Code: ${(error as Error).message}`);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment