<!DOCTYPE html>
<html>

  <head>
    <base href="." />
    <script type="text/javascript" charset="utf-8">
      window.AngularVersionForThisPlunker = 'latest'
    </script>
    <title>angular playground</title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <link rel="stylesheet" href="style.css" />
    <script src="https://unpkg.com/core-js@2.4.1/client/shim.min.js"></script>
    <script src="https://unpkg.com/zone.js@0.8.12/dist/zone.js"></script>
    <script src="https://unpkg.com/zone.js@0.8.12/dist/long-stack-trace-zone.js"></script>
    <script src="https://unpkg.com/reflect-metadata@0.1.3/Reflect.js"></script>
    <script src="https://unpkg.com/systemjs@0.19.31/dist/system.js"></script>
    <script src="config.js"></script>
    <script>
    System.import('app')
      .catch(console.error.bind(console));
  </script>
  </head>

  <body>
    <my-app>
    loading...
  </my-app>
  </body>

</html>
/* Styles go here */

.highlight {
  background-color: yellow;
  font-weight: 600;
}
### Angular Starter Plunker - Typescript



The Following Example includes : 
1. Filtering the data (i.e searching) from a list of available data and show the 
   result.

2. Highlighting the search result using Angular2 Pipe.











For More details visit

###                       https://learn-angular2.com                        ###
###                         Author: Abhishek Jha                            ###
### Reference : https://gist.github.com/adamrecsko/0f28f474eca63e0279455476cc11eca7 ###
var angularVersion;
if(window.AngularVersionForThisPlunker === 'latest'){
  angularVersion = ''; //picks up latest
}
else {
  angularVersion = '@' + window.AngularVersionForThisPlunker;
}

System.config({
  //use typescript for compilation
  transpiler: 'typescript',
  //typescript compiler options
  typescriptOptions: {
    emitDecoratorMetadata: true
  },
  paths: {
    'npm:': 'https://unpkg.com/'
  },
  //map tells the System loader where to look for things
  map: {
    
    'app': './src',
    '@angular/core': 'npm:@angular/core'+ angularVersion + '/bundles/core.umd.js',
    '@angular/common': 'npm:@angular/common' + angularVersion + '/bundles/common.umd.js',
    '@angular/compiler': 'npm:@angular/compiler' + angularVersion  + '/bundles/compiler.umd.js',
    '@angular/platform-browser': 'npm:@angular/platform-browser' + angularVersion + '/bundles/platform-browser.umd.js',
    '@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic' + angularVersion + '/bundles/platform-browser-dynamic.umd.js',
    '@angular/http': 'npm:@angular/http' + angularVersion + '/bundles/http.umd.js',
    '@angular/router': 'npm:@angular/router' + angularVersion +'/bundles/router.umd.js',
    '@angular/forms': 'npm:@angular/forms' + angularVersion + '/bundles/forms.umd.js',
    '@angular/animations': 'npm:@angular/animations' + angularVersion + '/bundles/animations.umd.js',
    '@angular/platform-browser/animations': 'npm:@angular/platform-browser' + angularVersion + '/bundles/platform-browser-animations.umd.js',
    '@angular/animations/browser': 'npm:@angular/animations' + angularVersion + '/bundles/animations-browser.umd.js',
    
    '@angular/core/testing': 'npm:@angular/core' + angularVersion + '/bundles/core-testing.umd.js',
    '@angular/common/testing': 'npm:@angular/common' + angularVersion + '/bundles/common-testing.umd.js',
    '@angular/compiler/testing': 'npm:@angular/compiler' + angularVersion + '/bundles/compiler-testing.umd.js',
    '@angular/platform-browser/testing': 'npm:@angular/platform-browser' + angularVersion + '/bundles/platform-browser-testing.umd.js',
    '@angular/platform-browser-dynamic/testing': 'npm:@angular/platform-browser-dynamic' + angularVersion + '/bundles/platform-browser-dynamic-testing.umd.js',
    '@angular/http/testing': 'npm:@angular/http' + angularVersion + '/bundles/http-testing.umd.js',
    '@angular/router/testing': 'npm:@angular/router' + angularVersion + '/bundles/router-testing.umd.js',
    'tslib': 'npm:tslib@1.6.1',
    'rxjs': 'npm:rxjs',
    'typescript': 'npm:typescript@2.2.1/lib/typescript.js'
  },
  //packages defines our app package
  packages: {
    app: {
      main: './main.ts',
      defaultExtension: 'ts'
    },
    rxjs: {
      defaultExtension: 'js'
    }
  }
});
//main entry point
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
import {AppModule} from './app';

platformBrowserDynamic().bootstrapModule(AppModule)
//our root app component
import {Component, NgModule, VERSION} from '@angular/core'
import {BrowserModule} from '@angular/platform-browser'
import { FormsModule }   from '@angular/forms';

import { Employee } from './src/employee'

import { MyFilterPipe } from './filter-data.directive'
import { HighlightPipe } from './highlight.directive'

@Component({
  selector: 'my-app',
  templateUrl: `./src/app.html`,
})
export class App {
  employeeData: Employee = [
    {
      id: "1234",
      name: "Abhishek Jha",
      company: "Persisten Sys"
      designation: "UI Developer"
    },
    {
      id: "1235",
      name: "Prashant kumar",
      company: "IBM"
      designation: "UI Developer"
    },
    {
      id: "2234",
      name: "Sonu Kumar",
      company: "Google"
      designation: "Software Developer"
    },
    {
      id: "1264",
      name: "Abhishek Verma",
      company: "Microsoft"
      designation: ".Net Developer"
    },
    {
      id: "1634",
      name: "Abinash",
      company: "Google"
      designation: "Software Developer"
    },
    {
      id: "1834",
      name: "Sourav Kumar",
      company: "Microsoft"
      designation: ".Net Developer"
    },
    {
      id: "1234",
      name: "Akhil",
      company: "IBM"
      designation: "Market Analyst"
    }
  ];
  data: string = "this is a simple paragraph that is meant to be nice and easy to type which is why there will be mommas no periods or any capital letters so i guess this means that it cannot really be considered a paragraph but just a series of run on sentences this should help you get faster at typing as im trying not to use too many difficult words in it although i think that i might start making it hard by including some more difficult letters I'm typing pretty quickly so forgive me for any mistakes i think that i will not just tell you a story about the time i went to the zoo and found a monkey and a fox playing together they."
  filterQuery: string = "";
  constructor() {
  }
}

@NgModule({
  imports: [ BrowserModule, FormsModule ],
  declarations: [ App, MyFilterPipe, HighlightPipe ],
  bootstrap: [ App ]
})
export class AppModule {}

<div class="container" style="margin-top: 50px;">
 <div class="form-group">
      <input type="text" class="form-control" placeholder="Enter Search text" [(ngModel)]="filterQuery">
</div>

<div class="row">
  <table class="table table-striped">
    <thead>
      <tr>
        <th>ID</th>
        <th>Name</th>
        <th>Company</th>
        <th>Designation</th>
      </tr>
    </thead>
    <tbody>
      <tr *ngFor="let employee of employeeData  | myfilter : filterQuery">
        <td [innerHTML]="employee.id | highlight: filterQuery"></td>
        <td [innerHTML]="employee.name | highlight: filterQuery"></td>
        <td [innerHTML]="employee.company | highlight: filterQuery"></td>
        <td [innerHTML]="employee.designation | highlight: filterQuery"></td>
      </tr>
    </tbody>
  </table>
</div>
  
</div>

import {PipeTransform, Pipe} from '@angular/core';

@Pipe({ name: 'highlight' })
export class HighlightPipe implements PipeTransform {
  transform(text: string, search): string {
    var pattern = search.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
    pattern = pattern.split(' ').filter((t) => {
      return t.length > 0;
    }).join('|');
    var regex = new RegExp(pattern, 'gi');

    return search ? text.replace(regex, (match) => `<span class="highlight">${match}</span>`) : text;
  }
}
import { Pipe, PipeTransform } from '@angular/core';

@Pipe({
    name: 'myfilter',
    pure: false
})
export class MyFilterPipe implements PipeTransform {
    transform(employees: any[], filterQuery: Object): any {
      console.log(JSON.stringify(employees));
        if (!employees || !filterQuery) {
            return employees;
        }
        // filter items array, items which match and return true will be kept, false will be filtered out
        return employees.filter(employee => employee.id.indexOf(filterQuery)> -1 ||
                                employee.company.toLowerCase().indexOf(filterQuery.toLowerCase()) > -1 || 
                                employee.name.toLowerCase().indexOf(filterQuery.toLowerCase()) > -1 || 
                                employee.designation.toLowerCase().indexOf(filterQuery.toLowerCase()) > -1);
        //return items.filter(item => item.title.indexOf(filter.title) !== -1);
    }
}
export interface Employee {
  id: string;
  name: string;
  company: string;
  designation: string;
}