- 
      
- 
        Save prabhakar711/c481ecc85af774def91bd5c97388c733 to your computer and use it in GitHub Desktop. 
    Angular2 text highlight pipe
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | import {PipeTransform, Pipe} from 'angular2/core'; | |
| @Pipe({ name: 'highlight' }) | |
| export class HighLightPipe implements PipeTransform { | |
| transform(text: string, [search]): string { | |
| return search ? text.replace(new RegExp(search, 'i'), `<span class="highlight">${search}</span>`) : text; | |
| } | |
| } | |
| /** Usage: | |
| * <input type="text" [(ngModel)]="filter"> | |
| * <div [innerHTML]="myAwesomeText | highlight : filter"></div> | |
| * | |
| */ | |
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment