ItSolutionStuff.com

How to Get Index of Ngfor in Angular?

By Hardik Savani • May 2, 2024
Angular

Hi All,

Now, let's see post of angular get index in ngfor. This article goes in detailed on how to get index in angular ngfor. Here you will learn how to get index in ngfor angular. if you have question about get index in ngfor angular 9/8 then i will give simple example with solution.

we can easily get index from ngform in angular 6, angular 7, angular 8, angular 9, angular 10, angular 11, angular 12, angular 13, angular 14, angular 15, angular 16 and angular 17 application.

I will give you very simple example so you can easily understand how to get index key in ngfor angular.

You can get index from ngfor as bellow:

let category of categories;let indexOfElem=index;

Example:

src/app/app.component.ts

import { Component } from '@angular/core';

@Component({

selector: 'my-app',

templateUrl: './app.component.html',

styleUrls: [ './app.component.css' ]

})

export class AppComponent {

name = 'Angular';

categories = [

{id: 1, name: 'JQuery'},

{id: 2, name: 'Angular'},

{id: 3, name: 'Vue'},

{id: 4, name: 'React'}

]

}

src/app/app.component.html

<h1>How to get index of ngfor in Angular? - ItSolutionStuff.com</h1>

<ul>

<li *ngFor="let category of categories;let indexOfElem=index;">

ngFor index: {{indexOfElem}} value : {{category.name}}

</li>

</ul>

You can see belloe output:

I hope it can help you...

Tags: Angular
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

Angular NgFor Example | NgFor Directive In Angular

Read Now →

Angular NgIf Else | Ng If Else in Angular Example

Read Now →

Angular Event Binding Example Tutorial

Read Now →

How to Create Service in Angular 8 using cli?

Read Now →

How to Redirect to Another Page in Angular?

Read Now →

Angular Http Post Request Example

Read Now →

Angular NgClass - How to Add Dynamic Class in Angular 10/9/8?

Read Now →