There is a variable that stores iframe code. I want to bind this in a div, but nothing work.
html:
<div class="top-image" [innerHTML]="yt"></div>
ts:
yt = '<iframe class="w-100" src="https://www.youtube.com/embed/KS76EghdCcY?rel=0&controls=0" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>';
What is the solution?
You probably might get a warning saying that it's unsafe HTML. That's why Angular is not rendering it inside the
div
.You'll have to
DomSanitize
it:Here's the pipe courtesy Swarna Kishore.
Here's a Sample StackBlitz.