JsBarcode icon indicating copy to clipboard operation
JsBarcode copied to clipboard

Generate barcode on Angular2 project

Open sarn3792 opened this issue 7 years ago • 7 comments

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 image

app.module.ts code: image

Does anyone know how to solve it? Thanks.

sarn3792 avatar Mar 14 '17 23:03 sarn3792

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.

lindell avatar Mar 15 '17 21:03 lindell

Check out ngx-barcode... built against angular4 but should work with 2 as well.

yobryon avatar May 09 '17 16:05 yobryon

@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 😄

lindell avatar May 09 '17 20:05 lindell

Anyone found a solution for that issue, because ngx-barcode is not compatible with angular2 :(

sebash1992 avatar Dec 02 '17 19:12 sebash1992

import * as JsBarcode from 'jsbarcode'; doesn't work?

SanichKotikov avatar Dec 02 '17 20:12 SanichKotikov

how can i use it once i do the import?

sebash1992 avatar Dec 03 '17 02:12 sebash1992

@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.

naressh avatar Mar 01 '18 11:03 naressh