I need help regarding iframes in angular 2.
Firstly embedding an iframe directly into a components template works fine.
<iframe
src='http://plnkr.co/edit/zZ0BgJHvQl5CfrZZ5kzg?p=preview | safeUrl'
allowtransparency='true'
frameborder='0'
scrolling='no'
width='80%'
height='500'>
</iframe>
Here is the code for the safeUrl pipe below
import { Pipe, PipeTransform } from '@angular/core';
import { DomSanitizationService } from "@angular/platform-browser";
@Pipe({
name: 'safeUrl'
})
export class SafeUrlPipe implements PipeTransform {
constructor(private sanitizer: DomSanitizationService) {
}
transform(url) {
return this.sanitizer.bypassSecurityTrustResourceUrl(url);
}
}
This all works fine.
The problem is when I want to load this iframe from the database angular throws an error and will not render the iframe
ERROR: browser_adapter.js:90WARNING: sanitizing HTML stripped some content (see http://g.co/ng/security#xss).
This Iframe is being fetched from a nosql database and is returned back to angular 2 nested inside HTML script.
Here is a example below of what is being fetch from the Database:
"<h2>Some text returned from the DB</h2>
<iframe
src='http://plnkr.co/edit/zZ0BgJHvQl5CfrZZ5kzg?p=preview | safeUrl'
allowtransparency='true'
frameborder='0'
scrolling='no'
width='80%'
height='500'>
</iframe>
<p>Some more text returned from the DB</p>"
Any Suggestions on how I can get this to render on angular 2 when returned from the database? Thanks.
Update
So this is how I am adding the Iframe nested inside a chunk of HTML code from the database to the {{ (post$ | async)?.description }} as seen below.
<h2>{{ (post$ | async)?.title }}</h2>
<div innerHTML="{{ (post$ | async)?.description }}" ></div>
Thanks!