0

I'm facing an issue I'm getting an string

const str = '<p>Please ensure Process Model diagram represents Functions adequately (boxes that represent an activity or group of activities that produce an outcome):</p><p><br></p><p><a href="https://www.google.com" rel="noopener noreferrer" target="_blank">Click here</a></p>'
<div [innerHTML]="str"></div>

I want to remove this paragraph and other HTML constructs, tried using innerHTML but its not stripping HTML elements, not sure why. How can we remove html elements and display text and link?

Alia
  • 9
  • 3

1 Answers1

2

You have to use DomSanitizer.

public str = this.sanitized.bypassSecurityTrustHtml('<p>Please ensure Process Model diagram represents Functions adequately (boxes that represent an activity or group of activities that produce an outcome):</p><p><br></p><p><a href="https://www.google.com" rel="noopener noreferrer" target="_blank">Click here</a></p>');

constructor(private sanitized: DomSanitizer) {}
N.F.
  • 3,844
  • 3
  • 22
  • 53
  • In addition to that, if the OP wanted to remove the outer div, they could use `outerHTML` instead of `innerHTML`. – Zlatko Jul 28 '23 at 08:46