Skip to content

Instantly share code, notes, and snippets.

@Walgermo
Created May 24, 2018 06:16
Show Gist options
  • Save Walgermo/f53794f1819be6ec74a57eae4449ad75 to your computer and use it in GitHub Desktop.
Save Walgermo/f53794f1819be6ec74a57eae4449ad75 to your computer and use it in GitHub Desktop.
Angular 2+ strip html pipe
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