Search
 
SCRIPT & CODE EXAMPLE
 

HTML

iframe in angular

In Component TS:

url = "https://www.urbanpro.com/kolkata/self-and-beyond-golf-green/4422880";

In Component HTML:

<iframe
      [src]="url | safe: 'resourceUrl'"
      height="600"
      width="1000"
    ></iframe>

Now create a safe pipe:

import { Pipe, PipeTransform } from "@angular/core";
import {
  DomSanitizer,
  SafeHtml,
  SafeStyle,
  SafeScript,
  SafeUrl,
  SafeResourceUrl,
} from "@angular/platform-browser";

@Pipe({
  name: "safe",
})
export class SafePipe implements PipeTransform {
  constructor(protected sanitizer: DomSanitizer) {}

  public transform(
    value: any,
    type: string
  ): SafeHtml | SafeStyle | SafeScript | SafeUrl | SafeResourceUrl {
    console.log(type);
    switch (type) {
      case "html":
        return this.sanitizer.bypassSecurityTrustHtml(value);
      case "style":
        return this.sanitizer.bypassSecurityTrustStyle(value);
      case "script":
        return this.sanitizer.bypassSecurityTrustScript(value);
      case "url":
        return this.sanitizer.bypassSecurityTrustUrl(value);
      case "resourceUrl":
        return this.sanitizer.bypassSecurityTrustResourceUrl(value);
      default:
        throw new Error(`Invalid safe type specified: ${type}`);
    }
  }
}
Comment

iframe render html in angular

yt = '<iframe class="w-100" src="https://www.youtube.com/embed/KS76EghdCcY?rel=0&controls=0" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>';
Comment

PREVIOUS NEXT
Code Example
Html :: html data-target modal 
Html :: SVG <line 
Html :: how to load at bottom of page html 
Html :: meta tag checker 
Html :: bootstrap css 
Html :: html tooltip attribute 
Html :: form submission with post 
Html :: atom html autocomplete 
Html :: ngbdatepicker disable input 
Html :: html make a cube 
Html :: html text color tag 
Html :: Hide table column using JavaScript 
Html :: html vertical text in table cell 
Html :: how to stop moving text in html when you hover over it 
Html :: html2pdf page break option 
Html :: %20 in html 
Html :: HTML how to create texts in body 
Html :: html title 
Html :: use disabled= in button 
Html :: h3 in html 
Html :: tab content bootstrap 4 
Html :: textarea 
Html :: convert html datetime-local to java LocalDateTime 
Html :: input type options html 
Html :: to ensure user input is a link in html 
Html :: html to exe 
Html :: html cheat sheet 
Html :: how to combine two input fields in html 
Html :: line break html 
Html :: smart contract spdx license 
ADD CONTENT
Topic
Content
Source link
Name
3+5 =