Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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
Javascript :: react-native-paper resize switch resize 
Javascript :: javascript log Time from Date 
Javascript :: npm 
Javascript :: adonis andwhere 
Javascript :: how to concurrently run angular and node 
Javascript :: jquery delete a cookie 
Javascript :: capital first letter react 
Javascript :: how to change react icon color 
Javascript :: react native status bar 
Javascript :: hide div js 
Javascript :: convert object to json javascript 
Javascript :: how to access xpath in js 
Javascript :: javascript check object methods 
Javascript :: odd even condition with ternary operator 
Javascript :: javascript check collision 
Javascript :: click button when press enter javascript 
Javascript :: generate unique id javascript 
Javascript :: defer parsing of javascript wordpress 
Javascript :: make link disabled in angular 
Javascript :: slug generator javascript 
Javascript :: javascript redirect to homepage 
Javascript :: jq get by name 
Javascript :: javascript get x,y point on circle 
Javascript :: json-server 
Javascript :: how to show only time in hours and minutes only in javascript 
Javascript :: convert functoin with call back to promise 
Javascript :: nodejs execute every minute 
Javascript :: how to get the next item in map() js 
Javascript :: js get childrens 
Javascript :: how to extract year from utc in javascript 
ADD CONTENT
Topic
Content
Source link
Name
9+8 =