Reputation: 35
I have a youtube iframe code.
<iframe width="560" height="315" src="https://www.youtube.com/embed/zfpmc-NnjXQ" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
How can i print only url from that iframe code in angular.
Please help.
Upvotes: 0
Views: 530
Reputation: 1733
Try something like this:
In ts file:
import { Component } from '@angular/core';
import { DomSanitizer, SafeResourceUrl } from '@angular/platform-browser';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ]
})
export class AppComponent {
name = 'Set iframe source';
url: string = "https://www.youtube.com/embed/zfpmc-NnjXQ";
urlSafe: SafeResourceUrl;
constructor(public sanitizer: DomSanitizer) { }
ngOnInit() {
this.urlSafe= this.sanitizer.bypassSecurityTrustResourceUrl(this.url);
}
}
In html file:
<hello name="{{ name }}"></hello>
<div style="text-align:center">
<h1>Reports</h1>
</div>
<iframe width="560" height="315" frameBorder="0" [src]="urlSafe"></iframe>
For more details: here
Upvotes: 1