libs/video-stat-dashboard/src/video-container/video-container-display.component.ts
selector | video-container-display |
templateUrl | ./video-container-display.component.html |
Properties |
Methods |
Inputs |
constructor(sanitizer: DomSanitizer)
|
||||||
Parameters :
|
currentVideo
|
Type: |
ngOnChanges | ||||||
ngOnChanges(changes: SimpleChanges)
|
||||||
Parameters :
Returns :
void
|
currentVideoUrl |
currentVideoUrl:
|
Type : SafeUrl
|
import { Component, Input, OnChanges, SimpleChanges } from '@angular/core';
import { DomSanitizer, SafeUrl } from '@angular/platform-browser';
import { Video } from '../+state/video-stats.interfaces';
const URLPREFIX = 'https://www.youtube.com/embed/';
@Component({
selector: 'video-container-display',
templateUrl: './video-container-display.component.html'
})
export class VideoContainerDisplayComponent implements OnChanges {
@Input() currentVideo: Video;
currentVideoUrl: SafeUrl;
constructor(private sanitizer: DomSanitizer) { }
ngOnChanges(changes: SimpleChanges) {
// good use of ngOnChanges - wire data through, around default sanitization
if (changes['currentVideo'] && changes['currentVideo'].currentValue) {
const incomingVideo = changes['currentVideo'].currentValue as Video;
this.currentVideoUrl = this.sanitizer.bypassSecurityTrustResourceUrl(URLPREFIX + incomingVideo.id);
}
}
}
<div class="card">
<div *ngIf="currentVideo" class="card-content">
<div class="card-title">{{currentVideo.title}} - {{currentVideo.author}}</div>
<div class="video-container">
<iframe width="560" height="315" [src]="currentVideoUrl" frameborder="0" allowfullscreen></iframe>
</div>
</div>
</div>