What is the best way to generate a variable amount of div elements with constantly changing content using Angular2?

I'm not entirely sure on the process, but I believe ngFor would be used in this scenario.

Essentially, my goal is to generate the following div multiple times, with each iteration updating the value inside the brackets from 0 to 1, 2, and so forth...

<div class="box">
    <p class="dut-text dut-title">
        {{list[0].data}}
    </P>
</div>

Answer №1

For every value in the array items, the following div is created:

<div class="box" *ngFor="let item of items; let i=index">
    <p class="dut-text dut-title">
        {{list[i].data}}
    </p>
</div>
class MyComponent {
  items = ['a', 'b', 'c'];
}

Update

An alternative way to interpret your question (check comments)

<div class="box" *ngFor="let item of list">
    <p class="dut-text dut-title">
        {{item.data}}
    </p>
</div>
class MyComponent {
  list = ['a', 'b', 'c'];
}

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

Creating a Runescape Tracker: What essentials should I include?

Hello everyone, I am a beginner in the world of programming and I am excited to learn. I have heard that the best way to learn is by working on a project. I have always been interested in creating a Skill Tracker for my clan. Can you offer any advice on wh ...

Applying CSS Styles to a Single Class Only

I have been using Zurb's Foundation to customize the navbar with my own styles, which has been successful so far. However, I encountered an issue with the responsive behavior of the navbar when the viewing container size changes. The navbar adds a sec ...

Node.js middleware for verifying required parameters

In my current application, I am utilizing node.js and express. I have developed multiple middleware functions, each one created in a similar fashion: function loadUser(req, res, next){ ... } I am interested in creating a middleware that can validate th ...

Are you delving into the realm of reduce functions in order to grasp the intric

Currently following this particular tutorial where they utilize the reduce method to transform an Array<Student> into a { [key: string]: Array<string | number> }. The tutorial includes this expression that caught my attention. It's quite n ...

Intercepting HTTP requests on specific routes with Angular 4+ using an HTTP Interceptor

I've developed an HTTP_INTERCEPTOR that needs to function on certain routes while excluding others. Initially, it was included in the main app module file. However, after removing it from there and adding it to specific modules, the interceptor conti ...

What are the steps for retrieving data on the server side by utilizing a token stored in localStorage?

Currently, I am diving into the official documentation for Next.js and utilizing the App router. On the data fetching patterns page, it explicitly states: Whenever possible, we recommend fetching data on the server To adhere to this recommendation, I cr ...

Creating a series of image files from CSS and Javascript animations using Selenium in Python

Looking to convert custom CSS3/Javascript animations into PNG files on the server side and then combine them into a single video file? I found an interesting solution using PhantomJS here. As I am not very familiar with Selenium, adapting it for use with S ...

Utilizing Input Value from Parent Component in Angular TypeScript File: A Guide

Is there a way to manipulate the @Input()items in the child-component.ts file before passing it to child-component.html? Currently experiencing an issue where I get an empty object when logging in the ngOnInit method. child-component.ts @Input()items: ...

What is the process for including a new item in a JavaScript dictionary?

I'm currently learning JavaScript and I've encountered a challenge. I have a dictionary that I'd like to update whenever a button is clicked and the user enters some data in a prompt. However, for some reason, I am unable to successfully upd ...

What is the method to make a file download using JavaScript?

In my jQuery ajax form, a user inputs their email and upon submission, they should receive an automatic download of a file. Here is the structure of the form: $(".email-form").submit(function(event) { event.preventDefault(); var $form = $(this), ...

Deploying a single Angular 5 project to various clients with unique URLs can streamline the development process

I am currently working on a new project using Angular 5.2 version. It has been deployed to the DEV location with the following URL: http://XX.XX.XX.XX/myDev/app/login When I execute the ng build command: ng build -aot -ec --prod --base-href=/myDev/ Now ...

Why does Typescript's 'await' seem to not wait as expected?

Apologies for the rookie mistake, I am currently transitioning from a C# background to Ionic, which may be causing some confusion on my end. I'm working on retrieving a stored token from Ionic storage but I'm struggling with understanding promise ...

Applying a dual background effect with one background repeating from the center using CSS3

I am trying to achieve a unique effect with CSS3 backgrounds. I want the second background image to start repeating from the middle of the screen down, rather than from the top. Below is my CSS code: body { background: url('../img/carbon_fibre.png ...

Enhancing SEO Performance with React Server Components

Exploring the new topic of React Server Components, which has recently been released, how does it impact SEO compared to SSR/Next.js? Unlike Next.js and traditional SSR where components are rendered statically on the server, React Server Components are re ...

sending a selection of JSON string values to a jQuery function

I have a JSON string that contains different items, but I am only interested in the 'locked' array and would like to pass it to a jQuery function. The JSON string was generated using json_encode from PHP. {"ignored":[],"status":{"message":"succe ...

What is causing my table to refuse to center?

I'm having trouble keeping my table of images contained within the content area of my page. Additionally, I can't seem to get my footer to stay at the bottom of the page. Take a look at this image for reference: body { margin: 0px; padding ...

Prevent the browser back button from being used in a web application that requires CLIENT_CERT authentication

My website utilizes CLIENT_CERT JAAS authentication and is compatible with IE7. After logging out, when I return to the home page and click on the back button, I want to stay on the same non-secure page. I have been able to achieve this using the history. ...

Things, their examples and the impact of setTimeOut

I'm currently delving into object oriented programming in JavaScript. function doStock() { //my class var that = this; var nAntiFreeze = null; // timeout ID var getContent = function(oInPageContainer) { GM_log('Antifreeze, before clea ...

Aligning the right menu of Ant Design from the Layout component

How can I align the menu to the right in antd? Please Note: The image has been edited using Photoshop and is not real. I attempted to declare a className = "Menu" and set .Menu {align-items: right;} but it didn't work. Here is the code snippet I use ...

What are some strategies for efficiently displaying a large amount of data on a screen using Javascript and HTML without sacrificing performance?

Imagine having a hefty 520 page book with over 6,200 lines of text ranging from 5 to 300 characters each. The challenge lies in efficiently displaying this content on the screen for users to read without causing lag or performance issues. Attempting to re ...