Iframe doesn't stop from reloading in Angular loop

after so long you must have found a solution, but I'll write the way I solved mine.

I encountered the same problem that you described and, in my case, the way that i solved it was to save the value of the url in a string instead of using a function.

So instead of having

<div [innerHTML]="trustContent(comment)">

i used

<div [innerHTML]="safeContent">

and in the component.ts

safeContent =  this.sanitizer.bypassSecurityTrustHtml(content);

This stopped the infinite loop for me


First of all, apologies for the late posting. Been very busy these past few weeks and I didn't have the luxury of time to post my answer up until now. Anyways... For the benefit of the those that might encounter this exact same issue, what worked for me was through the use of a pipe. So I've created a simple, custom pipe that transforms the given content and returns a safe and trusted html.

The Pipe:

import { Pipe, PipeTransform } from '@angular/core';
import { DomSanitizer } from '@angular/platform-browser';


@Pipe({ name: 'safe_html' })
export class SafeHtmlPipe implements PipeTransform {
  constructor(private sanitizer: DomSanitizer) {}
  transform(content) {
    return this.sanitizer.bypassSecurityTrustHtml(content);
  }
}

and then on the view, the content/comments are rendered as

<div [innerHTML]="comment.content  | safe_html"></div> 

Just to reiterate, the comments were outputted inside a loop.

Tags:

Iframe

Angular