Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular, How to use Variable For iframe source?

Tags:

html

angular

I want to use iframes from youtube and other similar platforms - but I can't find out how to use a variable as my source.

I've searched for it already, but the answers I got didn't work out.

So here is the iframe:

<div class="right">
    <h2>Associated Pictures/Media Files</h2>
    <p>Here we will display either Infos, Fotos, Videos, Music or even interative content.</p>
    <div style="padding: 2%;">
        <iframe 
        width="100%" 
        height="315" 
        src="https://www.youtube.com/embed/Q7hmXN714RQ" 
        frameborder="0" 
        allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" 
        allowfullscreen>
        </iframe>
    </div>
</div>

the only thing I want is to use this variable here:

import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  source = 'https://www.youtube.com/embed/Q7hmXN714RQ';
}       

But when I try to do it in various ways - like for example:

src="{{source}}"

this doesn't work at all :(

Does anyone know how to do this right? I cannot find a proper solution for this problem.

like image 821
Miger Avatar asked May 11 '26 21:05

Miger


1 Answers

What have you tried so far? Found this, maybe this works for you: https://stackblitz.com/edit/angular-youtube-video-in-iframe

like image 88
Ronald Korze Avatar answered May 14 '26 14:05

Ronald Korze



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!