This section explains the steps required to create a simple diagram and demonstrates the basic usage of the diagram control.
The following list of dependencies are required to use the BarcodeGenerator
component in your application.
|-- @syncfusion/ej2-barcode-generator
|-- @syncfusion/ej2-base
|-- @syncfusion/ej2-data
Essential JS 2 quickstart
project and install necessary packages by using the following commands.git clone https://github.com/syncfusion/ej2-quickstart.git quickstart
cd quickstart
npm install
BarcodeGenerator packages
should be mapped in the system.config.js
configuration file.System.config({
paths: {
'syncfusion:': './node_modules/@syncfusion/',
},
map: {
app: 'app',
//Syncfusion packages mapping
"@syncfusion/ej2-base": "syncfusion:ej2-base/dist/ej2-base.umd.min.js",
"@syncfusion/ej2-data": "syncfusion:ej2-data/dist/ej2-data.umd.min.js",
"@syncfusion/ej2-navigations": "syncfusion:ej2-navigations/dist/ej2-navigations.umd.min.js",
"@syncfusion/ej2-inputs": "syncfusion:ej2-inputs/dist/ej2-inputs.umd.min.js",
"@syncfusion/ej2-popups": "syncfusion:ej2-popups/dist/ej2-popups.umd.min.js",
"@syncfusion/ej2-buttons": "syncfusion:ej2-buttons/dist/ej2-buttons.umd.min.js",
"@syncfusion/ej2-lists": "syncfusion:ej2-lists/dist/ej2-lists.umd.min.js",
"@syncfusion/ej2-splitbuttons": "syncfusion:ej2-splitbuttons/dist/ej2-splitbuttons.umd.min.js",
"@syncfusion/ej2-barcode-generator": "syncfusion:ej2-barcode-generator/dist/ej2-barcode-generator.umd.min.js",
},
packages: {
'app': { main: 'app', defaultExtension: 'js' }
}
});
The project is preconfigured with common settings (
src/styles/styles.css
,system.config.js
) to start with all Essential JS 2 components.
Add the HTML div element for the Barcode into your index.html
. [src/index.html]
<!DOCTYPE html>
<html lang="en">
<head>
<title>EJ2 Barcode</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Typescript UI Controls" />
<meta name="author" content="Syncfusion" />
<link rel="shortcut icon" href="resources/favicon.ico" />
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<!--Style reference from app-->
<link href="/styles/styles.css" rel="stylesheet" />
<!--System js reference and configuration-->
<script src="node_modules/systemjs/dist/system.src.js" type="text/javascript"></script>
<script src="system.config.js" type="text/javascript"></script>
<link href="index.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
</head>
<body>
<!--container which is going to render the Barcode-->
<div id='container'>
</div>
</body>
</html>
Now, import the Barcode component into your app.ts
to instantiate a Barcode and append the diagram instance to the #container
. [src/app/app.ts]
The following example shows a basic Barcode.
import { BarcodeGenerator, ValidateEvent } from '@syncfusion/ej2-barcode-generator';
let barcode = new BarcodeGenerator({
width: '200px',
height: '150px',
mode: 'SVG',
type: 'Codabar',
value: '123456789',
});
barcode.appendTo('#element');
<!DOCTYPE html>
<html lang="en">
<head>
<title>EJ2 Barcode-Generator</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Typescript UI Controls" />
<meta name="author" content="Syncfusion" />
<link href="index.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
</head>
<style>
.barcodeStyle{
height: 150px;
width: 200px;
padding-left: 40%;
padding-top: 9%;
}
</style>
<body>
<div id='loader'>Loading....</div>
<div id='container'class="barcodeStyle">
<div id='element'></div>
</div>
</body>
</html>
Now, the npm run start
command is used to run the application in the browser.
npm run start
You can add the QR code in our barcode generator component.
import { QRCodeGenerator, ValidateEvent } from '@syncfusion/ej2-barcode-generator';
let barcode = new QRCodeGenerator({
width: '200px',
height: '150px',
displayText: { visibility: false },
mode: 'SVG',
value: 'Syncfusion',
});
barcode.appendTo('#element');
<!DOCTYPE html>
<html lang="en">
<head>
<title>EJ2 Barcode-Generator</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Typescript UI Controls" />
<meta name="author" content="Syncfusion" />
<link href="index.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
</head>
<style>
.barcodeStyle{
height: 150px;
width: 200px;
padding-left: 40%;
padding-top: 9%;
}
</style>
<body>
<div id='loader'>Loading....</div>
<div id='container'class="barcodeStyle">
<div id='element'></div>
</div>
</body>
</html>
You can add the datamatrix code in our barcode generator component.
import { DataMatrixGenerator, ValidateEvent } from '@syncfusion/ej2-barcode-generator';
let barcode = new DataMatrixGenerator({
width: '200px',
height: '150px',
displayText: { visibility: false },
mode: 'SVG',
value: 'Syncfusion',
});
barcode.appendTo('#element');
<!DOCTYPE html>
<html lang="en">
<head>
<title>EJ2 Barcode-Generator</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Typescript UI Controls" />
<meta name="author" content="Syncfusion" />
<link href="index.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
</head>
<style>
.barcodeStyle{
height: 150px;
width: 200px;
padding-left: 40%;
padding-top: 9%;
}
</style>
<body>
<div id='loader'>Loading....</div>
<div id='container'class="barcodeStyle">
<div id='element'></div>
</div>
</body>
</html>