Search
 
SCRIPT & CODE EXAMPLE
 

HTML

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
Html :: angular foreach 
Html :: add fav icon to website 
Html :: html center body 
Html :: How can I change the color of one word in HTML? 
Html :: how to create white space in html 
Html :: dutch phone pattern html 
Html :: video tag thumbnail 
Html :: html input only 4 digits 
Html :: span limit text length 
Html :: html template 
Html :: refresh html document every 30 seconds: 
Html :: linked image html 
Html :: html input type file accept excel 
Html :: bootstrap textarea width 
Html :: hide audio controls html 
Html :: clear html screen 
Html :: emmet unordered list 
Html :: pass text from input field to javascript function 
Html :: how to set an element affected by tab 
Html :: meta name= viewport 
Html :: my dixon earbuds are not in sync 
Html :: HOW TO USE A video on a html website from youtube 
Html :: ico html 
Html :: submit and open another page 
Html :: form multipart/form-data 
Html :: google translate for website html code 
Html :: markdown: text alignment and size 
Html :: input tag html with data list 
Html :: do you like grepper 
Html :: html strong 
ADD CONTENT
Topic
Content
Source link
Name
2+6 =