2017-12-19 13:53:46 +01:00
|
|
|
import {Component, ElementRef, Input} from '@angular/core';
|
|
|
|
import { SafeResourceUrl, DomSanitizer } from '@angular/platform-browser';
|
|
|
|
//Usage :: <i-frame [url]="url" width="30%" height="250"></i-frame>`
|
|
|
|
@Component({
|
|
|
|
selector: 'i-frame',
|
|
|
|
template: `
|
2020-05-05 12:37:36 +02:00
|
|
|
<div *ngIf="!style" class="iframeContainer uk-height-large">
|
|
|
|
<iframe [src]="safeUrl"></iframe>
|
|
|
|
</div>
|
|
|
|
<div *ngIf="style" class="iframeContainer" [ngStyle]="style">
|
|
|
|
<iframe [src]="safeUrl"></iframe>
|
2019-09-10 13:47:22 +02:00
|
|
|
</div>
|
2017-12-19 13:53:46 +01:00
|
|
|
`
|
|
|
|
})
|
|
|
|
export class IFrameComponent {
|
|
|
|
public safeUrl: SafeResourceUrl;
|
|
|
|
@Input() url ;
|
2020-05-05 12:37:36 +02:00
|
|
|
@Input() width: number;
|
|
|
|
@Input() height: number;
|
|
|
|
public style: any;
|
|
|
|
|
2017-12-19 13:53:46 +01:00
|
|
|
constructor(private sanitizer: DomSanitizer) {
|
|
|
|
}
|
|
|
|
ngOnInit() {
|
|
|
|
this.safeUrl = this.sanitizer.bypassSecurityTrustResourceUrl(this.url);
|
2020-05-05 12:37:36 +02:00
|
|
|
if(this.width && this.height) {
|
|
|
|
this.style = {
|
|
|
|
"width.px": this.width,
|
|
|
|
"height.px": this.height
|
2020-06-10 13:05:59 +02:00
|
|
|
};
|
|
|
|
} else if(this.height) {
|
|
|
|
this.style = {
|
|
|
|
"height.px": this.height
|
|
|
|
};
|
2020-05-05 12:37:36 +02:00
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
}
|