Ionic 4 | Adding ZBar Barcode / QR Code Scanner in Ionic 4 Application using Cordova and Native Plugin

In a previous post we have already discussed the most used QR Code and Barcode Scanner Native plugin for IOnic Application, but today we will use another very popular native plugin based on ZBar library.

This is a very good plugin to scan a variety of Barcode types including EAN-13/UPC-A, UPC-E, EAN-8, Code 128, Code 39, Interleaved 2 of 5 and QR Code

Letā€™s discuss implementation

Create a new Ionic 4 Application

$ ionic start Ionic4ZBarScanner blank
$ cd Ionic4ZBarScanner


Add Cordova and Ionic Nativ pluginĀ 

$ ionic cordova plugin add cordova-plugin-cszbar
$ npm install @ionic-native/zbar

Next, we need to include the pluginĀ in the app's main module file. Replace the following code inĀ app.module.tsĀ file.

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { RouteReuseStrategy } from '@angular/router';

import { IonicModule, IonicRouteStrategy } from '@ionic/angular';
import { SplashScreen } from '@ionic-native/splash-screen/ngx';
import { StatusBar } from '@ionic-native/status-bar/ngx';

import { AppComponent } from './app.component';
import { AppRoutingModule } from './app-routing.module';

import { ZBar } from '@ionic-native/zbar/ngx';

  declarations: [AppComponent],
  entryComponents: [],
  imports: [BrowserModule, IonicModule.forRoot(), AppRoutingModule],
  providers: [
    { provide: RouteReuseStrategy, useClass: IonicRouteStrategy }
  bootstrap: [AppComponent]
export class AppModule {}

Now in the Home page, we will add a button to call scan method and add scan method in home component file file

import { Component } from '@angular/core';

import { ZBar, ZBarOptions } from '@ionic-native/zbar/ngx';

  selector: 'app-home',
  templateUrl: '',
  styleUrls: [''],
export class HomePage {


    private zbar: ZBar
  ) {

    this.zbarOptions = {
      flash: 'off',
      drawSight: false


   .then(result => {
      console.log(result); // Scanned code
      this.scannedResult = result;
   .catch(error => {
      alert(error); // Error message


      Ionic 4 Barcode/ QR Code Scanner using ZBar

<ion-content padding>

    <ion-button (click)="scanCode()">Scan Code</ion-button>


Now you have added a Barcode scanner in Ionic 4 Application usingĀ ZBar native plugin. This will only work in the real device. RunĀ $ ionic cordova run android --deviceĀ command to check in USB connected the real device.

Also See:Ā Ionic 4 | Add Barcode/ QR Code Scanner/ Encoder Generator Ionic 4 Native Plugin


Notify of
1 Comment
Oldest Most Voted
Inline Feedbacks
View all comments

Thank you Freaky Jolly for this. Can get it to compile and run, but, does not scan consistently. Each time I scan the same code, I get a different result ?