feat: add barcode directive and register it in main module

This commit is contained in:
Azmat-7860
2026-11-08 18:02:04 +05:30
parent d8d0eb85cb
commit 7ecba598e1
3 changed files with 261 additions and 0 deletions
@@ -0,0 +1,30 @@
import { Directive, ElementRef, Input, OnChanges, SimpleChanges } from '@angular/core';
declare var JsBarcode: any;
@Directive({
selector: '[appBarcode]'
})
export class BarcodeDirective implements OnChanges {
@Input('appBarcode') value: string;
constructor(private el: ElementRef) {}
ngOnChanges(changes: SimpleChanges): void {
if (this.value && typeof JsBarcode !== 'undefined') {
try {
JsBarcode(this.el.nativeElement, String(this.value), {
format: 'CODE128',
height: 45,
width: 1.5,
displayValue: true
});
} catch (err) {
this.el.nativeElement.innerHTML = '';
}
} else {
this.el.nativeElement.innerHTML = '';
}
}
}
@@ -40,6 +40,7 @@ import { CKEditorModule } from 'ng2-ckeditor';
import { UserRegistrationComponent } from '../main/admin/user-registration/user-registration.component';
import { QRCodeModule } from 'angularx-qrcode';
import { BarcodeDirective } from './directives/barcode.directive';
import { TagInputModule } from 'ngx-chips';
import { CookieService } from 'ngx-cookie-service';
import { ImageCropperModule } from 'ngx-image-cropper';
@@ -121,6 +122,7 @@ import { DynamicFormViewerComponent } from './superadmin/dynamicform/dynamic-for
@NgModule({
declarations: [
BarcodeDirective,
MainPageComponent, PageNotFoundComponent, UserComponent, PasswordResetComponent,
MyworkspaceComponent,
ReportRunnerComponent, ReportrunnereditComponent, Reportrunneredit2Component, MenuGroupComponent, AllMenuGroupComponent, EditMenuGroupComponent, ReadOnlyMenuGroupComponent, UserRegistrationComponent,