Using Angular 6 to render an HTML tag using the ngFor directive and incorporating interpolation

I am facing a challenge with template rendering in Angular 6 and a library for creating floating panels called jsPanel 6, which is written in plain JavaScript. Essentially:

After my template is rendered, I have a BUTTON that triggers the following function:

public openPanel()
  {

    let list: Array<number> = [1, 2, 3];

    let tag : string = '<ul> <li *ngFor="let i of list"> {{ i }} </ul>';

      jsPanel.create({
        theme:       'primary',
        contentSize: {
            width: function() { return Math.min(730, window.innerWidth*0.9);},
            height: function() { return Math.min(400, window.innerHeight*0.5);}
        },
        position:    'center-top 0 250',
        animateIn:   'jsPanelFadeIn',
        headerTitle: 'I\'m a jsPanel',
        content:     tag,
        onwindowresize: true
    });

  }

The issue here is that Angular fails to render the ngFor directive properly; it doesn't iterate through the loop or perform the `{{ i }}` interpolation. For context, I am using TypeScript.

Here is the result after clicking the button.

Is there a way, without utilizing Dynamic Component Loader, to achieve the desired rendering?

Thank you.

Answer №1

It's clear that the current method is not functioning properly. Have you considered constructing HTML using JavaScript instead? Take a look at this approach:

public openPanel()
  {

    let list: Array<number> = [1, 2, 3];

    let tag: string = list.map(i => 
      `<ul><li>${i}</ul>`
    ).join('');

      jsPanel.create({
        theme:       'primary',
        contentSize: {
            width: function() { return Math.min(730, window.innerWidth*0.9);},
            height: function() { return Math.min(400, window.innerHeight*0.5);}
        },
        position:    'center-top 0 250',
        animateIn:   'jsPanelFadeIn',
        headerTitle: 'I\'m a jsPanel',
        content:     tag,
        onwindowresize: true
    });

  }

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

Steps for adding an object to an existing array of objects in a JSON format

My JSON object is dynamic and structured like the following, let data_existing= [ { "client":[ { "name":"aaaa", "filter":{ "name":"123456" } } ...

Improving the efficiency of JSON data retrieval in JavaScript

I possess a hefty 10MB JSON file with a structured layout comprising 10k entries: { entry_1: { description: "...", offset: "...", value: "...", fields: { field_1: { offset: "...", description: "...", ...

Issues arise with element binding when incorporating AngularJS UI-Router

My website utilizes AngularJS and UI-Router. To create a separate login page that is not injected into the main view, I decided to divide the index.html file into two parts: one with layout and script includes, and another with just script includes. This w ...

Display the div with a class only when jQuery is present

Recently, I've been encountering some issues with toggling the visibility of elements. On a single page, there are two popups and my goal is to hide one popup if the other has a certain class applied to it. <body class="home"> <div class=" ...

Getting data from an API with authorization in Next.js using axios - a step-by-step guide

click here to view the image user = Cookies.get("user") I'm having trouble accessing this pathway. I stored user data, including the token, using cookies. Please assist me with this issue. ...

employing document.write() specifically for a designated division

This is the coding: $(document).ready(function(){ var Jstr = { "JSON" : [ { "Eid" : 102,"Ename":"", "Ecode" : "<input type ='text'/>", "Eprops": {"name": "", "value":"", "maxlength":""}} ] } ; $(".search").click(funct ...

What is the reason behind having to include index 1 in the childNodes array when trying to access the initial child element?

I'm working on a JavaScript function that is supposed to display the text entered into an input field. Here is the code I have written: <head> <script type="text/javascript"> function showText() { var input = document. ...

Using Vue.js to mark a checkbox as selected

I've searched extensively and tried various combinations, but I'm unable to initialize my checkboxes as checked. For example: <ul class="object administrator-checkbox-list"> <li v-for="module in modules"> <label v-bin ...

Switch the icon in Angular 2 while using ngFor loop

One issue I am facing with my angular2 project is that the icon does not appear when the page loads, but only after clicking. The array being used is called "keys". <ion-grid class="dueD-line" *ngFor="let line of keys; let i=index"> <div style= ...

Preventing Internet Explorer from automatically scrolling to the top of the page when a new HTML element is dynamically inserted using

On my webpage, I have an ASP:Grid with a small copy button in each row to copy the text inside that cell. The javascript function I created for copying the text is as follows: var copyText = function (textToCopy) { $(".copy").append("<textarea id=&ap ...

RXJS - Implementing a conditional logic in the switchMap operator to determine if it's the first

In my service's http fetch method, there is a parameter called "showLoadingSpinner". When this parameter is set to false, the HttpContext DISABLE_LOADER_FOR_REQUEST = true will be set. I would like to set showLoadingSpinner to false for every subsequ ...

Rotating images with React

I am encountering an issue with implementing an image carousel in React. Previously, it worked perfectly when I was not using React, but now that I am migrating the page, I am facing an error. ** The carousel is located on the home page: ** const Home = ( ...

The onclick attribute on a button in HTML is not functioning properly following the inclusion of an Ajax load

I am facing an issue with a button that is being dynamically loaded from PHP code using Ajax. The button has an onclick attribute that calls a function named viewImage. The Ajax request is triggered every 5 seconds inside the loadImages function. Snippet ...

Assigning identical unique IDs to two transports in Winston

My project uses winston-js as a logger, and it's functioning well. However, I am now faced with the challenge of adding a unique log ID to each log line for debugging purposes. In my setup, I have two transports - 1) Console and 2) File. I want the ...

The functionality of jQuery is not functioning properly on dynamically created identical divs

I am currently working on creating a comment reply section. I have managed to load the same div for reply that I use for commenting by utilizing $('#1').append($('.enterComment').html());. In this case, 1 represents the id of the div th ...

What is the correct way to implement the chain populate method in a Node.js application?

I am developing a blog application with node.js and react, utilizing MongoDB and Mongoose's .populate method to fetch data across collections. Currently, I have three collections: Post, User, and Category. Successfully, I managed to link the username ...

"Encountered an issue while running the clean-css script in npm build

Encountering a peculiar error while running npm run build:prod today. "build:prod": "ng build --prod --aot=false --preserve-symlinks" The error message reads: 92% chunk asset optimizationC:\Projects\Latest_Feb26\ASSURE.OdyssEYGen2\Fr ...

The Typescript type does not include the specified properties even though they are declared as optional in the props

In my index.tsx file, I have defined the properties like so: interface Props { uuid: string cdn?: string filename?: any classname?: any [key: string]: any } export const UCImage = ({ uuid, cdn = 'https://ucarecdn.com/', filename, ...

How to Retrieve the Selected Value from an AngularJS UI-Select

At the moment, I am facing an issue with multiple dropdown directives that are using the same array of values. Whenever a selection is made in one dropdown, it updates the selected value in all other dropdowns. How can I ensure that each dropdown has a uni ...

Angular's scope allows for the application of CSS classes exclusively to the first div element

Every 2 seconds, a JavaScript function is being called that updates a specific div on the view when a certain condition is met. <div id="ball_{{ballIndex}}">{{ball}}</div> This is controlled by the ng controller. var myCounter = 0; ...