After the installation of the library you must copy the folder "fonts" from 'node_modules/bwip-js/'
to the '<your_app_folder>/src/assets' and rename it (the folder "fonts") to "bwipjs-fonts"
import { Component } from '@angular/core';
import bwipjs from 'bwip-angular2';
@Component({
selector: 'barcode',
template: `<button (click)="renderBarcode()">Click to render</button>
<canvas id="barcodeCanvas"></canvas>
<div id="err"></div>`,
styleUrls: ['./barcode-component.sass']
})
export class BarcodeComponent {
public renderBarcode(): void {
bwipjs('barcodeCanvas', {
bcid: 'code128',
text: '987654321',
scale: 3,
height: 10,
width: 10,
includetext: true,
textxalign: 'center',
}, (err, cvs) => {
if (err) {
document.getElementById('err').innerText = 'Error occured. See browser log for more information';
console.log(err);
} else {
}
});
}
}