I am using Angular 10. I have a scenario to get html string (value returned by rich text editor) and display it in my Application (using innerHtml). I'll be getting all kinds of styles, like background color, font-color, highlight text, hyperlinks etc.
I am using bypassSecurityTrustHtml via pipes (code is below) so that <styles> tags will be considered.
// sanitizeHtml.pipe.ts
@Pipe({ name: 'keepHtml', pure: false })
export class SanitizeHtmlPipe implements PipeTransform {
constructor(private sanitizer: DomSanitizer) {
}
transform(content) {
return this.sanitizer.bypassSecurityTrustHtml(content);
}
}
Now the problem is that when I get hyperlink texts <a href="http://www.someurl.com> click here </a>, these anchor links are not working. So, when I click on the link, it doesn't open the href link.
I've seen solutions like using bypassSecurityTrustResourceUrl. But I cannot use it as I won't be able to parse the url alone from the html content.
I also tried to use both the functions like below as suggested in other SO questions but it doesn't help either..
[innerHtml]="myHtmlContent | keepHtml | keepUrl"
[innerHtml]="myHtmlContent | keepUrl | keepHtml" // tried to reorder the pipe still didn't work
Is there a way to make the anchor tag's href links work while using bypassSecurityTrustHtml function?
Thanks for your time.