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 :: index for in angular 
Html :: Insert fav icon to head tag 
Html :: fav icon html 
Html :: html align text right 
Html :: html mail 
Html :: keywords html 
Html :: how to put autoplay music in the background of the page html 
Html :: img base 64 
Html :: middel click vuejs 
Html :: vue js focus ref 
Html :: centralizing to the middle of the screen with bootstrap 5 
Html :: how to make a background color in html 
Html :: html input file type csv 
Html :: laravel murakkab old request 
Html :: how to make links in html 
Html :: buttons in video tag html 
Html :: how to call a function as soon as a page loads javascript 
Html :: stop bubbling 
Html :: pass method jsf component 
Html :: <meta name="viewport" content="width=device-width, initial-scale=1.0" 
Html :: css keep hyphenated words together 
Html :: how to make bootstrap cards centered 
Html :: measures have been taken to increase their number. 
Html :: am pm time html javascript 
Html :: bootstrap 3 button 
Html :: remove underline from a tag 
Html :: chrome remove autocomplete highlight 
Html :: predefine data list in input tag 
Html :: react render string as html 
Html :: thymeleaf import in html 
ADD CONTENT
Topic
Content
Source link
Name
9+5 =