Getting started with Angular Barcode component
7 Aug 20245 minutes to read
This section explains you the steps required to create a simple barcode and demonstrate the basic usage of the barcode control.
Setup Angular Environment
You can use Angular CLI
to setup your Angular applications.
To install Angular CLI use the following command.
npm install -g @angular/cli
Create an Angular Application
Start a new Angular application using below Angular CLI command.
ng new my-app
cd my-app
Installing Syncfusion Barcode Generator package
Syncfusion packages are distributed in npm as @syncfusion
scoped packages. You can get all the Angular Syncfusion package from npm link.
Currently, Syncfusion provides two types of package structures for Angular components,
- Ivy library distribution package format
- Angular compatibility compiler(Angular’s legacy compilation and rendering pipeline) package.
Ivy library distribution package
Syncfusion Angular packages(>=20.2.36
) has been moved to the Ivy distribution to support the Angular Ivy rendering engine and the package are compatible with Angular version 12 and above. To download the package use the below command.
Add @syncfusion/ej2-angular-barcode-generator
package to the application.
npm install @syncfusion/ej2-angular-barcode-generator --save
Angular compatibility compiled package(ngcc)
For Angular version below 12, you can use the legacy (ngcc) package of the Syncfusion Angular components. To download the ngcc
package use the below.
Add @syncfusion/ej2-angular-barcode-generator@ngcc
package to the application.
npm install @syncfusion/ej2-angular-barcode-generator@ngcc --save
To mention the ngcc package in the package.json
file, add the suffix -ngcc
with the package version as below.
@syncfusion/ej2-angular-barcode-generator:"20.2.38-ngcc"
Note: If the ngcc tag is not specified while installing the package, the Ivy Library Package will be installed and this package will throw a warning.
Adding Syncfusion Barcode Generator package
All the available Essential JS 2 packages are published in npmjs.com
registry.
To install Barcode Generator component, use the following command.
npm install @syncfusion/ej2-angular-barcode-generator --save
The –save will instruct NPM to include the barcode generator package inside of the
dependencies
section of thepackage.json
.
Adding Barcode Generator control
You can start adding Essential JS 2 barcode-generator component to the application. To get started, add the Angular Barcode component in app.ts
and index.html
files using the following code.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { BarcodeGeneratorAllModule,QRCodeGeneratorAllModule,DataMatrixGeneratorAllModule } from '@syncfusion/ej2-angular-barcode-generator'
import { Component } from "@angular/core";
@Component({
imports: [
BarcodeGeneratorAllModule, QRCodeGeneratorAllModule ,DataMatrixGeneratorAllModule
],
providers: [ ],
standalone: true,
selector: "app-container",
// specifies the template string for the barcode generator component
template: `<ejs-barcodegenerator style="display: block;" #barcode id="barcode" width="200px" height="150px" mode="SVG" type="Codabar" value="123456789">`
})
export class AppComponent {}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Adding QR Generator control
You can add the QR code in our Angular Barcode Generator component.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { BarcodeGeneratorAllModule,QRCodeGeneratorAllModule,DataMatrixGeneratorAllModule } from '@syncfusion/ej2-angular-barcode-generator'
import { Component } from "@angular/core";
@Component({
imports: [
BarcodeGeneratorAllModule, QRCodeGeneratorAllModule ,DataMatrixGeneratorAllModule
],
providers: [ ],
standalone: true,
selector: "app-container",
// specifies the template string for the barcode generator component
template: `<ejs-qrcodegenerator style="display: block;" #barcode id="barcode" width="200px" height="150px" mode="SVG"value="Syncfusion"></ejs-qrcodegenerator>`
})
export class AppComponent {}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Adding Datamatrix Generator control
You can add the datamatrix code in our Angular Barcode Generator component.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { BarcodeGeneratorAllModule,QRCodeGeneratorAllModule,DataMatrixGeneratorAllModule } from '@syncfusion/ej2-angular-barcode-generator'
import { Component } from "@angular/core";
@Component({
imports: [
BarcodeGeneratorAllModule, QRCodeGeneratorAllModule ,DataMatrixGeneratorAllModule
],
providers: [ ],
standalone: true,
selector: "app-container",
// specifies the template string for the barcode generator component
template: `<ejs-datamatrixgenerator style="display: block;" #barcode id="barcode" width="200px" height="200px" mode="SVG"
type="DataMatrix" value="Syncfusion">
</ejs-datamatrixgenerator>`
})
export class AppComponent {}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
You can refer to our Angular Barcode Generator feature tour page for its groundbreaking feature representations. You can also explore our Angular Barcode Generator example that shows how to render the Barcode in Angular.