replace html tag from description


Fri Apr 14 2023 09:53:55 GMT+0000 (Coordinated Universal Time)

Saved by @vaibhavugale76 #angular #pipe

<p>{{ lesson?.description | replaceHtmlTags }}</p>
import { Pipe, PipeTransform } from '@angular/core';

@Pipe({ name: 'replaceHtmlTags' })
export class ReplaceHtmlTagsPipe implements PipeTransform {
  transform(html: string): string {
    return html.replace(/<\/?[^>]+(>|$)/g, '');
  declarations: [ReplaceHtmlTagsPipe],
  // ...
export class AppModule { }

This pipe uses a regular expression to match and replace any HTML tags with an empty string. The | character in the regular expression is used to match either an opening tag < or a closing tag >, and the [^>]+ expression is used to match any characters that are not >, allowing for matching tags with attributes. Make sure to declare this pipe in the declarations array of your module so it can be used in your templates: