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 :: ngfor with index 
Html :: Add fav icon to browser tab 
Html :: input required 
Html :: elementor text control 
Html :: libcuinj64-9.1 : Depends: libcuda1 (= 387.26) 
Html :: html form action target blank 
Html :: Ion-img in center of screen 
Html :: external js 
Html :: <input length 
Html :: html mailto link with content 
Html :: meta refresh 
Html :: fa fa file 
Html :: can get input value from dangerouslysetinnerhtml 
Html :: hint text html 
Html :: html file input accept excel file 
Html :: bootstrap navbar-inverse not working 
Html :: how to navigate to another page in html 
Html :: ol text align 
Html :: what file extension sould you use to save a website 
Html :: What is a viewport meta tags 
Html :: how to check where was the changes in a perticuler commit git 
Html :: bs bg color 
Html :: html5 iframe youtube loop 
Html :: open link in a new tab 
Html :: html input checkbox example 
Html :: jQuery script tag to include into HTML 
Html :: how to program a button to work in javascript 
Html :: predefine data list in input tag html 
Html :: como cambiar la fuente de letra en html 
Html :: integer input html 
ADD CONTENT
Topic
Content
Source link
Name
1+6 =