try this:
Online demo
Safe Pipe
import { Pipe, PipeTransform } from '@angular/core';
import { DomSanitizer} from '@angular/platform-browser';
@Pipe({ name: 'safe' })
export class SafePipe implements PipeTransform {
constructor(private sanitizer: DomSanitizer) {}
transform(url: string) {
return this.sanitizer.bypassSecurityTrustResourceUrl(url);
}
}
AppComponent
import {Component} from '@angular/core';
@Component({
selector: 'app-root',
template: `
<iframe [src]="'https://www.youtube.com/embed/' + testRequestId | safe" width="560" height="315" allowfullscreen></iframe>
`
})
export class AppComponent {
testRequestId: string = 'uelHwf8o7_U';
}
because Angular not trust any source, it'll sanitize the content, then we need bypass it.
Learn more about this topic: https://angular.io/docs/ts/latest/guide/security.html
Template syntax