Use external js lib (jsBarcode)



I need to import this lib in my Ionic2 project (JsBarcode - a Barcode generation library written in JavaScript).

Can someone help me?
I can not import and use the functions.

Best regards.


You’d install the package from npm

npm install jsbarcode --save

Then import it into your project

import { Component, ViewChild, ElementRef } from '@angular/core';
import JsBarcode from 'jsbarcode';
  selector: 'page-home',
  templateUrl: 'home.html'
export class HomePage {
  public picture;
  @ViewChild('barcode') barcode: ElementRef;
  ) {

   JsBarcode(this.barcode.nativeElement, '12345');

<ion-content padding>
  <svg #barcode id="barcode"></svg>


Thank you so much!
It works like a charm!

ps: why we need this? public picture;


heh, must have been leftover from some testing I did earlier.


Can you show how to convert the barcode to image?
trying to do it using canvas but stuck