Search
 
SCRIPT & CODE EXAMPLE
 

TYPESCRIPT

ngfor index

<ul>
    <li *ngFor="let item of items; let i = index" [attr.data-index]="i">
        {{item}}
    </li>
</ul>
Comment

how to get index for ngfor

*ngFor="let item of items; index as i;" 
// OR
*ngFor="let item of items; let i = index;"
// i will be the index, starting from 0 
// and you can show it in the string interpolation with {{ i }}
Comment

ngfor index

<ul>
    <li *ngFor="let item of items; index as i">
        {{item}}
    </li>
</ul>
Comment

ngfor index

<ul>
  <li *ngFor="let food of menu; index as i">
      {{ index }},{{ food }}
  </li>
</ul>
<!-- index starts from 0 
This gives an undordered list of food items in a menu, with the first item as 0-->
Comment

ngfor index

<ul>
    <li *ngFor="let item of items; let i = index" [attr.data-index]="i">
        {{item}}
        {{i}}
    </li>
</ul>
Comment

index in ng for

You have to use let to declare the value rather than #.

<ul>
    <li *ngFor="let item of items; let i = index" [attr.data-index]="i">
        {{item}}
    </li>
</ul>
Angular = 1
<ul>
    <li *ngFor="#item of items; #i = index" [attr.data-index]="i">
        {{item}}
    </li>
</ul>
Comment

PREVIOUS NEXT
Code Example
Typescript :: typescript replace 
Typescript :: cube numbers list 
Typescript :: @babel/preset-typescript 
Typescript :: ionic 3 open link external 
Typescript :: how to display server count on discord.js 
Typescript :: reduce an array of objects to string 
Typescript :: python how to check if all elements in list are the same 
Typescript :: get local storage data in angular 
Typescript :: function that redirects to another page react 
Typescript :: mat dialog block scroll 
Typescript :: components meaning 
Typescript :: window ethereum types 
Typescript :: how to check if its a character in r 
Typescript :: drop table if exists redshift 
Typescript :: sort two lists that refence each other 
Typescript :: @react-navigation/native route typescript 
Typescript :: type script encode url 
Typescript :: react typescript onclick type 
Typescript :: too many requests jquery laravel 
Typescript :: jupyter notebook create table 
Typescript :: typescript object key enum 
Typescript :: how to check is null or empty in typescript 
Typescript :: typescript break for each 
Typescript :: array with objects read element with the lowest value 
Typescript :: typescript with babel 
Typescript :: form reset typescript 
Typescript :: nodejs aws s3 upload 
Typescript :: generics functional component 
Typescript :: increase space between border dots css 
Typescript :: typescript interface property multiple types 
ADD CONTENT
Topic
Content
Source link
Name
6+8 =