Created
October 23, 2019 02:04
-
-
Save pertrai1/a48b8ff82621efb8ffb79ff8a3c61429 to your computer and use it in GitHub Desktop.
Angular 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 HTML | |
* 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