Best practices for updating content within div elements using Angular's ngFor directive

My List consists of integer array type values, being displayed using *ngFor:

<div *ngFor="let item of values; let i = index">
  <div> 
     <div *ngFor="let subitem of item;" style="display:block">
       <div class="progress">
            <div class="progress-bar" id="progress" role="progressbar" aria-valuenow="70" aria-valuemin="0" aria-valuemax="100" [style.width.%] = "subitem">
              {{subitem}}
            </div> 
       </div>
       <br>
   </div>
</div>

To avoid unnecessary creation of div elements, I aim to show the list contents within a single div after a delay, rather than repeated iterations.

Answer №1

To achieve the same outcome, you can use the code snippet below:

    <div class="progress">
        <div class="progress-bar" id="progress" role="progressbar" aria-valuenow="70" 
                 aria-valuemin="0" aria-valuemax="100" [style.width.%] = "subitem">
          {{subitem}}
        </div> 
    </div>

This is how it can be implemented in TypeScript:

  for(let i=0; i <= item.length; i++) {
     setTimeout((subitem) => {
        this.subitem = subitem;
      },i * yourTimeOfIntervale, item[i])
  }

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

I am not sure where the file is stored between selecting it for upload and actually uploading it

Currently, I am developing a web application using C#, Angular, and SQL. I am in the process of creating a feature that allows users to upload an Excel file into the database by clicking a button on the frontend. Upon clicking the button, a dialog box open ...

Using Tailwind classes as a prop functions correctly, however, it does not work when directly applied

Here's a component snippet I'm working on: export const TextInput = ({ label, wrapperClassName = "", inputClassName = "", labelClassName = "", placeholder = "", ...props }: InputProps & Fiel ...

Conceal a specific segment on the web page if the API call in Angular does not return any data

I'm currently working with data retrieved through an API call and I need assistance in implementing code to hide a section when there is no data being fetched. Could you provide a sample code for this? ...

Angular 12 experiencing CSS alignment issues

In my Angular component, I have the following CSS: .folders { border-left: 5px solid #b8744f; -moz-border-radius: 5px; -webkit-border-radius: 5px; -moz-box-shadow: inset 0 0 1px #fff; -webkit-box-shadow: inset 0 0 1px #fff; /*CORRECTION NEEDED ...

Angular keeps the routing parameters consistent throughout

I've encountered an issue with a button I created that directs the user to an overview page using a parameter called "Id". The problem I'm facing is that after selecting a user and then going back to select a different user, it still retains the ...

Is it possible to assign an alternative name for the 'require' function in JavaScript?

To ensure our node module is executable and includes dependencies for requiring modules at runtime, we utilize the following syntax: const cust_namespace = <bin>_require('custom-namespace'); This allows our runtime environment to internal ...

Applying the spread operator in the map function for copying objects

In my Angular application, I am attempting to copy an object and add a new property using the spread operator. To add the new property, I have created a method called 'addNewProperty(name)' which returns the property and its value. However, when ...

Customized IntelliSense naming for overloaded parameters with conditional tuple types

In TypeScript 3.1, I have a generic function with arguments of either (TInput, string) or (string), depending on whether the generic's type parameter TInput extends undefined. To achieve this, I'm utilizing the new generic rest parameters feature ...

Enhancing a component with injected props by including type definitions in a higher-order component

Implementing a "higher order component" without types can be achieved as shown below: const Themeable = (mapThemeToProps) => { return (WrappedComponent) => { const themedComponent = (props, { theme: appTheme }) => { return <Wrapped ...

Which is better in Angular2: defining default property values in the constructor or inline?

When it comes to creating an object class in Angular 2, the common dilemma is whether to initialize values inline or within a constructor. But what exactly is the difference between the two approaches? export class Foo { id: string; name: string = &ap ...

When attempting to compile the building project following the upgrade to Angular 9, an error message is displayed stating "Unable to access property 'length' as it is undefined

I'm currently in the process of updating my Angular 9 project by following the migration guide on update.angular.io. After running ng update @angular/core @angular/cli, I encountered an error "ERROR in Cannot read property 'length' of undefi ...

Effortlessly apply mapping, filtering, reducing, and more in JavaScript

Array#map and Array#filter both create a new array, effectively iterating over the original array each time. In languages like rust, python, java, c#, etc., such expression chains only iterate once, making them more efficient in certain cases. While this ...

Allowing cross-origin resource sharing (CORS) in .NET Core Web API and Angular 6

Currently, I am facing an issue with my HTTP POST request from Angular 6. The request is successfully hitting the .net core Web API endpoint, but unfortunately, I am not receiving the expected response back in Angular 6. To make matters worse, when checkin ...

Angular resolver does not return anything if the outcome is an observable generated using the .asObservable() method

While working on my project, I wanted to simulate my http calls by using a BehaviorSubject along with Observable properties in my resolver service. However, I faced an issue and I am not sure why this code snippet is not functioning as expected: schedule- ...

Obtain document via Angular 2

Is it possible to use TypeScript to download an image that is already loaded? <div *ngIf="DisplayAttachmentImage" class="fixed-window-wrapper_dark"> <button class="btn btn-close-window" (wslClick)="HideAttachmentImage()"> & ...

Breaking down an array into function arguments in TypeScript/JavaScript

I am working with an array of object instances that have different types. var instances: any = []; instances["Object1"] = new TypeA(); instances["ObjectB"] = new TypeB(); Each type has its own methods with unique names and varying numbers of arguments. I ...

How to ensure Angular mat-button-toggle elements are perfectly aligned within their respective groups

https://i.stack.imgur.com/Wjtn5.png Hello there, I'm trying to make the numbers in the first group match the style of the second group (noche, mañana...). I've set both the group and individual element width to 100%, but the numbers beyond 22 ...

Bring life to the angular page

Within my home and register components, I have implemented a unique design feature. The home component showcases pagination floating along the rightmost side from top to bottom with a yellow background color. Additionally, there is a prominent register but ...

Create an interface object in TypeScript with no initial properties

I'm currently developing an app with angular 5 (TS) and I've encountered a problem while trying to initialize an empty object of my interface. The solution that I found and attempted is as follows: article: Article = {} as Article; However, ...

Encountering TS2304 error message while running TypeScript files indicates the inability to locate the name 'PropertyKey', in addition to another error - TS2339

I encountered an issue while attempting to execute a spec.ts file in the Jasmine Framework. After installing @types/core-js version 0.9.46 using the command npm i @types/core-js, I started receiving the following error messages: > ../../node_modules/ ...