Guide on retrieving URL from backend to iframe with Angular Material selection change

https://i.sstatic.net/mWBb5.png

This is an .html page

<iframe width="100%" height="100%" src="{{url}}" frameborder="0" allowfullscreen></iframe>

Here is the code for a .ts file

this.url = 'https://www.youtube.com';

Whenever a selection is changed from the dropdown list, the iframe src should be updated based on the new url.

Answer №1

When working on a .html page

<iframe width="100%" class="embed-responsive-item" height="100%" src="" frameborder="0" allowfullscreen></iframe>

And in the .ts file

import ElementRef from '@angular/core';

To initialize it, use the following code in the constructor

constructor(private hostElement: ElementRef)

Add these lines wherever you want this to be triggered.

const iframe = this.hostElement.nativeElement.querySelector('iframe');
iframe.src = 'https://www.youtube.com';

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Typescript: Enhance your coding experience with intelligent parameter suggestions for functions

Within a nest.js service, there is a service method that takes an error code and generates a corresponding message to display to the user. The example below shows a simplified version of this method: getGenericErrorMessage(input: string): string { co ...

Issue with Angular custom toggle functionality not functioning properly on mobile devices

I've been working on creating a custom toggle feature in Angular. While everything runs smoothly on desktop, I'm encountering issues on mobile devices. On desktop, the toggle works by clicking and dragging to the right, whereas on mobile, it shou ...

Filter the JSON data within every mat-tab section

Can someone help me with displaying the data from these JSON objects? [ { "defectClassification": "Wrong Color", "sample": 0, "defect": "CRITICAL" }, { "defectClassification": "Delamination", "sample": 0, ...

How to defer the rendering of the router-outlet in Angular 2

I am currently working on an Angular 2 application that consists of various components relying on data fetched from the server using the http-service. This data includes user information and roles. Most of my route components encounter errors within their ...

React Query successfully retrieves the path, but unfortunately fails to render the image in the display

Currently facing an issue where I am trying to retrieve images from the backend using ReactQuery. Here is the ReactQuery code snippet: export const useGetProductImagesByProductId = (productId: string) => useQuery({ queryKey: ['productIm ...

How can I establish default values for 2 to 3 options in a Dropdownlist?

Is there a way to set two values as default in a dropdown list, and when the page is refreshed, the last two selected values are retained as defaults? Thanks in advance! Visit this link for more information ...

Construct this node project utilizing either gulp or webpack exclusively

In the structure of my project, you will find various folders like node, build, gulp, and src. These folders contain important files for the development process such as .gitignore, gulpfile.js, package.json, tsconfig.json, webpack.config.js, server.js, con ...

Regular expression for the validation of emails using a delimiter

Can someone help me create a regex expression for emails? This is what I have so far: \S+@\S+\.\S+ I want to repeat this X times with a ; separator. Any ideas on how to achieve this? For example, the pattern should allow strings like: ...

What is the process for loading a JSON file using VueJS and Typescript?

I am facing an issue with loading a JSON file in my new VueJS project. Reproduction / Issue To easily reproduce the issue, I have created a Github repository: https://github.com/devedse/VueJSImportJsonFile In the Home.vue page, I am trying to get the JS ...

Is it possible to use a type assertion on the left hand side of an assignment in TypeScript?

While reading the TypeScript documentation, I came across type assertions but it seems they are limited to expressions only. I am looking to assert the type of a variable on the left side of an assignment statement. My specific scenario involves an Expres ...

Error encountered when trying to use the .find function in Typescript: "The expression is not callable."

Environment Details: typescript 4.5.5 Error Summary An issue occurred stating: "This expression is not callable. Each member of the union type '{ <S extends User>(predicate: (this: void, value: User, index: number, obj: User[]) => value ...

Bringing in personalized data types using unique import aliases

Recently, I made changes to my Next.js project by upgrading it to TypeScript. One of the modifications I made was updating my import alias from @/* to @*. Below is the new configuration in my tsconfig.json. { "compilerOptions": { "targ ...

What is the method for expanding an object type using a string literal type?

I am encountering an issue with the code snippet below. In this code, type B is meant to extend type A by expanding the acceptable values for the property type. However, despite this intention, the assignment is resulting in a type error. type A = { ...

The Typescript function unexpectedly returns a NaN value even though it should be returning a

Having an issue with my countdown timer function: startTimer(duration) { this.myTimer = duration; setInterval(function () { this.myTimer--; console.log("TIMER: " + typeof(this.myTimer) + " " + this.myTimer); }, 1000); } When I ...

The initial invocation of OidcSecurityService.getAccessToken() returns null as the token

Our internal application requires all users to be authenticated and authorized, including for the home page. To achieve this, we use an HttpInterceptor to add a bearer token to our API requests. Initially, when rendering the first set of data with the fir ...

The argument provided is a string type, which cannot be assigned to a parameter expecting an object with a 'results' property of type string

When attempting to pass the result.nativeEvent.message to another function, I am encountering the error: Argument of type 'string' is not assignable to parameter of type '{ results: string; } on onUnityMessageController(result.nativeEvent.me ...

Prevent the element attribute from being enabled before the onclick function is triggered

I am attempting to implement a feature in Angular that prevents double clicking on buttons using directives. Below is the pertinent code snippet from my template: <button (click)="onClickFunction()" appPreventDoubleClick>Add</button> And her ...

Issues with mat-input functionality within a mat-table in Angular 8

I'm encountering an issue with my mat-table. The input field within the table is not functioning properly. All rows are sharing the same input field, so when I type text into the box, it appears in all rows. Here is my code: <ng-container matColum ...

Tips on Configuring the Attributes of a TypeScript Object in Angular 2

A TypeScript class called Atom is defined as follows: export class Atom { public text: String; public image: boolean; public equation: boolean; } To create an object of type Atom class and set its properties, the following steps are used: atom: ...

A more concise approach to accessing a generic class method in Typescript

Let's analyze the code snippet below: export class BaseClass<T> { property = this.buildProperty(); buildProperty(){ return someBuilder<T>(); } } Through TypeScript, the type of property is automatically determined based on the ...