Pass html / html through variable "sanitizer.bypassSecurityTrustResourceUrl" in Angular

0

--------- iframe.component.ts --------

import { Component, OnInit } from '@angular/core';
import { DomSanitizer, SafeResourceUrl, SafeUrl } from '@angular/platform-browser';

@Component({
  selector: 'app-iframe',
  templateUrl: './iframe.component.html',
  styleUrls: ['./iframe.component.css']
})

export class IframeComponent implements OnInit {

  dangerousUrl: string;
  trustedUrl: SafeUrl;
  dangerousVideoUrl: string;
  videoUrl: SafeResourceUrl;

  constructor(private sanitizer: DomSanitizer) {

    this.dangerousUrl = 'javascript:alert("Hi there")';
    this.trustedUrl = sanitizer.bypassSecurityTrustUrl(this.dangerousUrl);
    this.updateVideoUrl('PUBnlbjZFAI');

  }
updateVideoUrl(id: string) {

    this.dangerousVideoUrl = 'https://play.google.com/about/developer-content-policy/#!?modal_active=none';//Aqui es donde quiero insertar el html para luego pasarlo al iframe

    this.videoUrl =
        this.sanitizer.bypassSecurityTrustResourceUrl(this.dangerousVideoUrl);
  }
  ngOnInit() {
  }

}

--------- iframe.component.html ------

<div class="embed-container">
   <iframe class="e2e-iframe-trusted-src" width="640" height="390" [src]="videoUrl"></iframe>
</div>

---------- example.json ----------

{
    "ejemplo": "8.40",
    "ejemplo1": "3.76",
    "ejemplo2": "0.79",
    "url": "<html><body><h1>HOLA MUNDO</h1></body></html>",
    "ejemplo3": ""
}
    
asked by Rai 01.12.2017 в 11:20
source

0 answers