What is the most effective way to display individual items from an NgFor one by one using Angular?

Currently, I am working on an ngfor loop with three items and my goal is to present them in a step-by-step format, similar to how questions are displayed in a form. For example, I want the second question to only show up once the first step has been completed.

If you need a reference, I have included a StackBlitz code that you can view: https://stackblitz.com/edit/angular-ivy-oauzgh?file=src%2Fapp%2Fapp.component.html

Answer №1

There may be a more efficient approach than using ngFor for this task, but you could try implementing the following code snippet:

<tr *ngFor="let hero of heroes; let i = index">
   <td *ngIf="i > currentIndex">{{hero.name}}</td>
   Perform an action to update the currentIndex value accordingly
</tr>

In your typescript file, make sure to initialize the currentIndex variable as 0 and create a function that increments the index when triggered by the corresponding HTML block.

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

Error Message: Unexpected character "C" found in JSON response from Ionic 2 Http GET request

Trying to execute a GET request and extract data from the response. this.http.get('http://localhost:8888/maneappback/more-items.php').subscribe(res => { console.log(res.json()); }, (err) => { console.log(err); }); An error message ...

NPM displaying an error message

npm ERROR! Windows_NT 6.3.9600 npm ERROR! Command "C:\\Program Files (x86)\\nodejs\\\\node.exe" "C:\\Program Files (x86)\\nodejs\\node_modules\\npm\\bin\\np ...

What is the recommended TypeScript type to be returned from a GraphQL resolver when using ESLint?

Repository Link https://github.com/inspiraller/apollo-typescript The code is functioning correctly, however, Eslint typescript is raising complaints. An eslint error occurs on the following code block: Query: { players: () => players } Miss ...

Using TypeScript to declare ambient types with imported declarations

In my TypeScript project, I have a declaration file set up like this: // myapp.d.ts declare namespace MyApp { interface MyThing { prop1: string prop2: number } } It works perfectly and I can access this namespace throughout my project without ...

Transform a literal string type definition into a string value (similar to the typeof operator), or is it the other way around in TypeScript?

Is there a way to retrieve the string value of a string literal type without having to define it twice, similar to the typeof operator in C#? myStringLiteral: 'STRING TYPE'; myString: string = typeof(myStringLiteral); // I want myString to be e ...

Using TypeScript generics with the `keyof` operator may result in rejection

I created a custom method using the RXJS library which looks like this : function Subject<T>(t: T):T { return t; } In addition, I defined an interface that specifies the structure of my application values. Additional keys can be added to this i ...

Embarking on the journey of using SASS, SCSS, and Bootstrap within an Angular project

Just dipping my toes into the world of Bootstrap and SASS, so any guidance on setting it up properly would be greatly appreciated. I've recently started an Angular project in Visual Studio 2019. Bootstrap is specified in package.json like this: " ...

The search is on for the elusive object that Angular 2/4

Why am I encountering the error message saying "Cannot find name 'object'"? The error message is: Error: core.service.ts (19,23): Cannot find name 'object'. This error occurs in the following line of code: userChange: Subject<ob ...

Tips for arranging columns and rows in a mat-dialog box

In my Angular project, I am working on a mat dialog box and trying to achieve a layout with 1 row at the top and 3 rows at the bottom, similar to the image below. However, I am facing issues in making it work properly. Additionally, I want to hide the hori ...

Waiting for nested observables to complete in Angular 2

Before proceeding to another page in my Angular app, I need two nested Observables to complete. However, I am facing synchronization issues as they are nested within each other. These Observables are initialized in my authentication service. authentication ...

Developing a hover-triggered tooltip feature in a React application

A tooltip has been created that appears when hovering over an element, displaying the full name of the product called productName. <div className="product-select-info" onMouseEnter={e => productNameHandleHover(e)} onMouseLeave={productNameHand ...

Is there a way to create a universal getter/setter for TypeScript classes?

One feature I understand is setting getters and setters for individual properties. export class Person { private _name: string; set name(value) { this._name = value; } get name() { return this._name; } } Is there a w ...

Having trouble with unresponsive pages when adjusting filters

My page loads dynamic charts from an API, each chart represents different equipment such as A01, A02, etc. These charts display uptime and downtime data with over 300 records. However, when I change the filter to yearly, which fetches more records from th ...

Using Axios and Typescript to filter an array object and return only the specified properties

I'm currently working on creating an API to retrieve the ERC20 tokens from my balance. To accomplish this, I am utilizing nextjs and axios with TypeScript. However, I'm encountering an issue where the response from my endpoint is returning exces ...

Angular 2: Emptying input field value on click event

I am experiencing an issue with resetting my input values. I have a search bar with filter functions. When I enter a value, it displays a list below and I want to add a function to these links. When I click on one of them, it takes me to another component ...

Which is the best option: Service variable, Service Observable, or Service Subject?

Lately, I've been contemplating the idea of global variable declaration, and I'm struggling to see the advantage of using a Subject in a service instead of a simple variable or even an Observable. Could you help me understand why someone would ch ...

Using ngForm to implement multiselect options in HTML

Attempting to implement a multiselect dropdown that is tied to a dynamic property receiving data from a JSON script via service. Successfully displayed the data in the dropdown, but encountering abnormalities when adding the multiple attribute within the s ...

Executing installed packages using npm: A step-by-step guide

Recently, I have encountered a confusing issue in my coding journey. In Python, I got used to installing packages and using them right away without any hiccups. For example, with SpotDL, everything worked seamlessly. However, things took a different turn w ...

The functionality of Angular 5 reactive form valueChanges is not functioning correctly

I am currently working with a form inside a service: this.settingsForm = this.formBuilder.group({ names: this.formBuilder.array([]), globalIDs: this.formBuilder.array([]), topics: this.formBuilder.array([]), emails: thi ...

Sign up for a service that sends out numerous simultaneous requests for every item in a list

I am encountering an issue with my Angular 5 component that is responsible for displaying a list of items. The items are fetched from a service and populated in the component by subscribing to the service. The service first makes a request to retrieve the ...