Generating HTML tags on-the-fly in Angular 2

Is it possible to generate an HTML tag dynamically within a component's template?

For example:

template:`<{{custom_tag}} [info]="info"></{{custom_tag}}>`
...
this.custom_tag="example";
this.info={};

The resulting HTML would look like this:

<example info="..."></example>

Answer №2

Apologies for the delay, but here is my response:

To add a new component, you can create it and then use its selector tag wherever necessary.

For example:

@Component({
  selector: 'app-example',
})
export class ExampleComponent implements OnInit {}

Use the selector like this:

<app-example></app-example>

To pass parameters to the new component:

 <app-example [param]="abc"></app-example>

Make sure to identify the input param with the same identifier 'param' using the @input() property.

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

Spirit.py navigates using javascript

Having trouble with Ghost.py. The website I'm trying to crawl uses javascript for paginated links instead of direct hrefs. When I click on the links, selectors are the same on each page so Ghost doesn't wait since the selector is already present. ...

Utilizing Three.js to import models directly from a database

Currently, I have a MySQL database containing FBX models. The client-side of my application is able to read these models from the database. However, the model data is stored in a JavaScript variable. How can I utilize THREE.FBXLoader() to load the model da ...

How to bypass CORS restrictions in XMLHttpRequest by manipulating HTTP headers?

Currently experimenting with the (deprecated) Twitter API 1.0 For instance, I am interested in retrieving data from the API utilizing AJAX browser requests on cross-origin web pages. This could be a new tab, a local HTML file, or any established website. ...

Unfortunately, CSS3 PIE is not compatible with border-radius and box-shadow properties

I created a basic HTML/CSS code for testing purposes, but I'm having trouble getting the library to function properly. I've placed the .htc, .php and .js files in the same directory as index.html, but it just won't work. Check out the code ...

What is the process for transferring a Pulumi Output<T> to the container definition of a task in ECS?

When creating a generic ECS service that deals with dynamic data, it is important to note that the containerDefinition within a Task Definition must be provided as a single valid JSON document. The code snippet for this setup looks like: genericClientServi ...

Experience the power of TypeScript in a serverless environment as you transform your code from

I have some JavaScript code that needs to be converted to TypeScript. Currently, I have two files: API_Responses.js const Responses = { _200(data = {}) { return { statusCode: 200, body: JSON.stringify(data), }; } }; module.export ...

Is the ajaxToolkit PopupControlExtender malfunctioning? Could it be due to being outdated?

I recently tried following a tutorial on using ASP.NET Ajax Popup Control to display GridView row details. However, I encountered a runtime error when attempting to perform a mouseover action. The error message reads: Sys.ArgumentUndefinedException: Va ...

Implementing the "$store" property within Vue components

Click here for a guide on how to type the $store property. Unfortunately, I've been encountering issues with it. In my Vue 2 project created using vue-cliI, I included a vuex.d.ts file in ./src directory but the $store property in my components still ...

How to prevent sorting in a specific column in an Angular <mat-table>

I currently have a mat-table that includes the matSort attribute. From my understanding, this attribute enables sort headers for all columns. However, I am wondering if there is a way to disable the sort header for just one specific column? When using < ...

Unable to manipulate imported objects in three.js, anime.js, and gltfloader - troubleshooting in progress

UPDATE: I have created a new demo to provide more clarity on the issue. This demonstration combines two existing fiddles that exhibit the same problem. Desired outcome: My goal is for the imported object to be accessible in the same manner as 'cube&a ...

Would you like to learn how to dynamically alter a button's color upon clicking it and revert it back to its original color upon clicking it again?

My Upvote button starts off transparent, but when I click on it, the background color changes to green. What I need is for the button to become transparent again when clicked a second time. I've attempted using the following code snippet: function ...

Is there a way to find the magnitude of a whole number without relying on the Math.abs function?

Is there a method to obtain the absolute value of a number without utilizing math.abs? Here is my current approach: function absValue(number) { var abs = number * number; return Math.sqrt(abs); } ...

What could be causing my AJAX form to refresh the page upon submission?

I have been working on a basic Follow/Unfollow system, and although the functionality is working correctly in terms of inserting and deleting rows when following/unfollowing, I'm facing an issue where the page refreshes every time despite using e.prev ...

Execute AJAX function following the completion of table loading from PHP in Ajax

I'm currently working on a shopping cart feature that involves calculating certain figures based on table values. The process involves loading the table using AJAX and PHP, which is functioning properly. However, I'm facing an issue where I nee ...

Utilize the JSON response upon successful completion of an AJAX request

I'm currently working with this code snippet: function openIzmeni(value) { $.ajax({ url: "getRzaizmenu.php", type: "POST", async: true, data: { vrednostid:value}, //your form data to post goes here as ...

Troubleshooting Responsive Design Problem on iPad with Angular 8 P-dialog

https://i.sstatic.net/6IW6X.pngWe recently implemented the PrimeNG p-dialog box for our project. It works well on regular desktop sizes, with the maximize and close buttons easily accessible. However, we noticed that when viewing on an iPad, these button ...

Embed a script into an iframe from a separate domain

While experimenting, I attempted to inject a script inside an iframe element using the following method. However, since the child and parent elements do not belong to the same domain (and I am aware that XSS is prevented in modern browsers), I was wonder ...

I am looking to modify various attributes linked to Rails

My Desire for Reality I am looking to update multiple related values in Rails by sending an update request from JavaScript. While creating data was seamless, I encountered difficulties when attempting to update it. #Code JavaScript* export const actions ...

Tips for adding an HTML code snippet to an HTML iframe with the help of jQuery

Is there a way to dynamically append an HTML code snippet to an HTML iframe using jQuery? I have stored an HTML code snippet in a MySQL Database using PHP, and I am now attempting to retrieve that snippet and add it to the iframe using jQuery. $( document ...

Controlling the Flow of Events in JavaScript Documents

Explore the integration of two interconnected Javascript files and delve into managing event propagation between them effectively. 1st js file var red = [0, 100, 63]; var orange = [40, 100, 60]; var green = [75, 100, 40]; var blue = [196, 77, 55]; var ...