Created
January 13, 2020 07:38
-
-
Save Dominent/7094885dd5e4ddbf9e277fcfc392d83f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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