Angular 2 has the possibility to make a string be interpreted as html?

0

I have a variable called "link_youtube", which contains a data similar to this:

<iframe width="640" height="360" src="https://www.youtube.com/embed/eNs5g-c1Qno?list=RDeNs5g-c1Qno"frameborder="0" allowfullscreen></iframe>

But the browser does not identify this as an html, it identifies as a string, I need my system to identify this as an HTML, could anyone help me?

Below is the html code:

insira o código aqui
<div class="text-center">
    <h1>{{sPCrtl.campanha.titulo}}</h1>
    {{sPCrtl.campanha.biografia_campanha.link_youtube}}">
</div>
    
asked by anonymous 28.08.2017 / 15:30

1 answer

0

Try:

<div [innerHtml]="iframeYoutube"></div>

UPDATE

You really need more stuff to insert an iframe, already tested with normal html, but iframe the angle blocks right away. Sorry for the shallow answer.

You need to inject the DomSanitizer of angular in order to inject your iframe:

iframeYoutube: SafeHtml;

Create a variable of type SafeHtml of package @angular/platform-browser

Inject DomSanitizer , also of package @angular/platform-browser , into the constructor of your component:

constructor(
  ...
  private sanitizer: DomSanitizer,
  ...
) {}

And finally the moment you inject the iframe into the div do

iframeYoutube = this.sanitizer.bypassSecurityTrustHtml('<iframe width="560" height="315" src="youtube.com/embed/2dAY9dh-HWo"; frameborder="0" allowfullscreen></iframe>');
    
28.08.2017 / 15:32