javascript - Angular 4 | iframe to be populated in innerHTML -


i have problem

i have subscribed api returns html content. has iframes. however, iframe not loading , instead showing string in browser. please check below code

component file

this._emittersservice.longdescemitted$.subscribe(obj => {   this.longdesc = obj;  });` 

html file

<div class="description-panel" [innerhtml]="longdesc" ></div>

problem: when

this.longdesc = "<iframe width="something" height="something" src="something" ></iframe>"

this displayed string, not detecting has iframe. need angular allow rendered html.

step1 : import below part in ts file

import {domsanitizer} '@angular/platform-browser'; 

step 2 :define constructor in perticular ts file

constructor(private domsanitizer:domsanitizer) {} 

step 3:-use below code in ts file according requirement (method/ function or constructor)

this._emittersservice.longdescemitted$.subscribe(obj => {       this.longdesc = this.domsanitizer.bypasssecuritytrusthtml(obj or html content); or  this.longdesc = this.domsanitizer.bypasssecuritytrusthtml('<iframe width="something" height="something" src="something" ></iframe>')      }); 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -