Skip to content

Instantly share code, notes, and snippets.

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