In today’s fast-paced world, efficiency is critical. Integrating barcode scanning into your Ionic (Angular) application can significantly streamline your workflow, whether managing inventory, processing transactions, or simply tracking data. This guide will walk you through effortlessly setting up a barcode scanner in your Ionic (Angular) application using the Capacitor ML Kit.

Setting Up the Environment

Before diving into the implementation, ensure you have the necessary environment set up:

  1. Install Dependencies: Make sure you have Angular and Capacitor installed in your Ionic project. If not, you can install them using npm:
    npm install -g @angular/cli npm install @capacitor/core @capacitor/cli
  2. Initialize Capacitor: Initialize Capacitor in your Ionic project by running:
    npx cap init
  3. Install Capacitor ML Kit Barcode Scanning: Install the Capacitor ML Kit Barcode Scanning plugin in your project:
    npm install @capacitor-mlkit/barcode-scanning

Implementing Barcode Scanning

Let’s implement barcode scanning in your Ionic (Angular) application. Below is a sample code demonstrating how to integrate barcode scanning functionality:

import { Component, NgZone, OnInit } from '@angular/core';
import { FormControl, FormGroup } from '@angular/forms';
import { Barcode, BarcodeScanner, LensFacing, BarcodeFormat } from '@capacitor-mlkit/barcode-scanning';

  selector: 'app-barcode-scanning',
  templateUrl: './',
  styleUrls: ['./'],
export class BarcodeScanningPage implements OnInit {
  public readonly barcodeFormat = BarcodeFormat;
  public readonly lensFacing = LensFacing;
  public isPermissionGranted = false;
  public isSupported = false;
  public formGroup = new FormGroup({
    formats: new FormControl([]),
    lensFacing: new FormControl(LensFacing.Back),
    googleBarcodeScannerModuleInstallState: new FormControl(0),
    googleBarcodeScannerModuleInstallProgress: new FormControl(0),
  public barcodes: Barcode[] = [];

    private ngZone: NgZone,
  ) {}

  public ngOnInit() {
    BarcodeScanner.isSupported().then((result) => {
      this.isSupported = result.supported;
    BarcodeScanner.checkPermissions().then((result) => {
      this.isPermissionGranted = === 'granted';
    BarcodeScanner.removeAllListeners().then(() => {
        (event) => {
 => {
            const { state, progress } = event;
              googleBarcodeScannerModuleInstallState: state,
              googleBarcodeScannerModuleInstallProgress: progress,


  public async scan(): Promise<void> {
    const formats = this.formGroup.get('formats')?.value || [];
    const { barcodes } = await BarcodeScanner.scan();
    this.barcodes = barcodes;

  public async installGoogleBarcodeScannerModule(): Promise<void> {
    await BarcodeScanner.installGoogleBarcodeScannerModule();


This tutorial demonstrated how to effortlessly integrate barcode scanning into your Ionic (Angular) application using Capacitor ML Kit. By following these steps, you can enhance the functionality of your app and streamline various processes. Whether you’re building a retail app, inventory management system, or any application that requires barcode scanning, this integration will help you achieve a seamless user experience.

Now, implement barcode scanning in your Ionic (Angular) app and witness the efficiency it brings to your workflow!

Read More Blog

Quick Game