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 :: add fav icon to website 
Html :: add favicon to website html 
Html :: html sms link android 
Html :: email link html 
Html :: set textbox into center of div in bootstrap 
Html :: multi line comment html 
Html :: default date in html 
Html :: checked bootstrap 5 
Html :: how to make a clickable image in html 
Html :: html insert remote image 
Html :: datalayer push 
Html :: html page scroll horizontal problem 
Html :: action button dropdown 
Html :: how to read a form from HTML in javascript 
Html :: econnreset 127.0.0.1 
Html :: Checkbox checked border radius CSS 
Html :: what to put in http equiv in html 
Html :: copyright in html 
Html :: minmax length password 
Html :: bootstrap position class 
Html :: html checkbox default checked 
Html :: jinja avoid auto escape 
Html :: input width autosize 
Html :: whitespace code 
Html :: koa get url params 
Html :: bootstrap hyperlink 
Html :: flutter html to pdf 
Html :: usehistory is not exported from react-router-dom 
Html :: at sign html 
Html :: how to make a youtube video on a website 
ADD CONTENT
Topic
Content
Source link
Name
5+4 =