Angular 14 Search Filter Pipe with NG2 Search Filter Tutorial

Angular search filter pipe example, this step by step article will explain how to create an angular search pipe filter with the help of ng2-search-filter library from scratch.

Search filter are useful in finding the desired results in a large dataset. A user types some text, and the result manifests on the screen based on matched input.

In this comprehensive guide, you will learn to effortlessly create the search pipe and later implement the search filter in the angular app.

Angular pipe filter example will be explained in this article. We will create a custom search using a pipe to filter table data dynamically using the user name.

Consequently, without further ado, lest start seeing how to create a custom search in Angular with third-party search filter plugin and angular pipe filter.

Angular 14 Search Filter Example

  • Step 1: Configure Angular Environment
  • Step 2: Install Search Filter Plugin
  • Step 3: Register Ng2SearchPipeModule
  • Step 4: Create Search Filter in Angular
  • Step 5: Test Application

Configure Angular Environment

Before creating an angular app, you must install angular CLI:

npm install -g @angular/cli

Create the new angular app with recommended command:

ng new angular-demo

Head over to app’s root:

ng new angular-demo

Disable Strict Angular TypeStrict Errors

The latest version of Angular comes with strict mode, you have to manually disable the strict mode you can set “strict”: false, "noImplicitReturns": false and "strictTemplates": false inside the compilerOptions and angularCompilerOptions in tsconfig.json file.

Install Search Filter Plugin

This is the quintessential step so install the third party search filter package with npm command:

npm install ng2-search-filter

Register Ng2SearchPipeModule in App Module

Import Ng2SearchPipeModule and FormsModule simultaneously at the top additionally register both the modules in imports array in app.module.ts file:

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

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

import { Ng2SearchPipeModule } from 'ng2-search-filter';
import { FormsModule } from '@angular/forms';

  declarations: [
  imports: [
  providers: [],
  bootstrap: [AppComponent]

export class AppModule { }

Create Search Filter in Angular

Angular filter pipe picks a subset of items from an array hence add the filter pipe in the table along with ngFor directive, also run the for loop directive to iterate over the Users list.

Update below code in app.component.html:

<div class="form-group">
  <input type="text" class="form-control" placeholder="Type to search" [(ngModel)]="data">

<table class="table">
      <th scope="col">ID</th>
      <th scope="col">Name</th>
      <th scope="col">Email</th>
    <tr *ngFor="let item of Users | filter:data">

Go ahead and open the app.component.ts and update the suggested code:

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

  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']

export class AppComponent {

  data: string;

  Users = [{
      "id": 5440,
      "name": "Wanda Lynch",
      "email": ""
      "id": 6228,
      "name": "Katrina Graves",
      "email": ""
      "id": 1654,
      "name": "Louis Daniels",
      "email": ""
      "id": 1631,
      "name": "Gavin Sullivan",
      "email": ""
      "id": 9880,
      "name": "June Martinez",
      "email": ""
      "id": 8634,
      "name": "Owen Davis",
      "email": ""
      "id": 3918,
      "name": "Megan Harrison",
      "email": ""
      "id": 3680,
      "name": "Joel Thompson",
      "email": ""
      "id": 2409,
      "name": "Dora Rose",
      "email": ""
      "id": 4477,
      "name": "Candice Neal",
      "email": ""

We added the Users array and added some dummy data into it.

Start Application

Eventually, open console execute the suggested command to start the development server:

ng serve

Run the app using the given below url:



This guide helped us comprehend how to quickly create a search filter pipe in angular using the ng2 search filter pipe.

I reckon it must have helped you understand the concepts of creating this primary feature.