JsBarcode
JsBarcode copied to clipboard
Generate barcode on Angular2 project
Hi.
I want to use generate a barcode using typeScript and angular2 project.
I've already run npm install jsbarbode --save
. After that, I added the reference to the script in angular-cli.json
"scripts": [ "../node_modules/jsbarcode/dist/JsBarcode.all.js" ],
When I add the module in app.module.ts the following error is shown
app.module.ts code:
Does anyone know how to solve it? Thanks.
JsBarcode uses commonJS (not ES6 modules). To get it to work right now it seems like you need to change things in your toolchain with something like systemjs.
I thought that there was a wrapper library for angular2 but it seems to only exist two angular 1 ones.
I will keep this issue open until I or someone else creates a library to easy a JsBarcode compontent into angular 2. Until then, if you solve the issue, please share it for others to see.
Check out ngx-barcode... built against angular4 but should work with 2 as well.
@yobryon That's very nice. Now there exist wrappers for all major frontend frameworks, angular1, angular2, react and vue. Will probably add them all to the readme soon 😄
Anyone found a solution for that issue, because ngx-barcode is not compatible with angular2 :(
import * as JsBarcode from 'jsbarcode';
doesn't work?
how can i use it once i do the import?
@sarn3792 , you can do this by the below code. It is working for me.
declare let JsBarcode: any;
it should be declared before the @Component or export class
then you can call the JsBarcode like below,
JsBarcode("#barcode", "Hello");
Note: include the JsBarcode.all.min.js in your src assets and include the path in index.html
Good luck.