Created
May 24, 2018 06:16
-
-
Save Walgermo/f53794f1819be6ec74a57eae4449ad75 to your computer and use it in GitHub Desktop.
Angular 2+ strip html pipe
This file contains 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 { Pipe, PipeTransform } from '@angular/core'; | |
/* | |
* Strips HTM | |
* Takes an input parameter HTML. | |
* Usage: | |
* content | striphtml | |
* Example: | |
* <p [innerHTML]="content | striphtml"></p> | |
*/ | |
@Pipe({ | |
name: 'striphtml' | |
}) | |
export class StripHtmlPipe implements PipeTransform { | |
transform(value: any): any { | |
if ((value === null) || (value === '')) { | |
return ''; | |
} else { | |
return value.replace(/<(?:.|\n)*?>/gm, ' '); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment