Project

General

Profile

1
import {Component, ElementRef, Input} from '@angular/core';
2
import { SafeResourceUrl, DomSanitizer } from '@angular/platform-browser';
3
//Usage :: <i-frame [url]="url" width="30%" height="250"></i-frame>`
4
@Component({
5
  selector: 'i-frame',
6
  template: `
7
    <div  *ngIf="!style" class="iframeContainer uk-height-large">
8
      <iframe allowtransparency="true"   [src]="safeUrl"></iframe>
9
    </div>
10
    <div *ngIf="style"  class="iframeContainer" [ngStyle]="style">
11
      <iframe [src]="safeUrl"></iframe>
12
    </div>
13
  `
14
})
15
export class IFrameComponent {
16
  public safeUrl: SafeResourceUrl;
17
  @Input() url ;
18
  @Input() width: number;
19
  @Input() height: number;
20
  @Input() unit: string = 'px';
21
  public style: any;
22
  
23
  constructor(private sanitizer: DomSanitizer) {
24
  }
25
  ngOnInit() {
26
    this.safeUrl = this.sanitizer.bypassSecurityTrustResourceUrl(this.url);
27
    let width = 'width.' + this.unit;
28
    let height = 'height.' + this.unit;
29
    if(this.width && this.height) {
30
      this.style = {};
31
      this.style[width] = this.width;
32
      this.style[height] = this.height;
33
    } else if(this.height) {
34
      this.style = {};
35
      this.style[height] = this.height;
36
    }
37
  }
38
}
(10-10/22)