Hello I have this loop in angular in need to find the index of post so I can delete it?
*ngFor="let post of posts"
Asked
Active
Viewed 735 times
0

Igli
- 15
- 1
- 8
-
2Does this answer your question? [ngFor with index as value in attribute](https://stackoverflow.com/questions/35405618/ngfor-with-index-as-value-in-attribute) – spots Jun 19 '20 at 15:58
2 Answers
2
Try to use index
<div *ngFor="let item of items; let i = index">
{{i}}
</div>

Norbert Bartko
- 2,468
- 1
- 17
- 36
2
There are multiple local variables in the *ngFor
directive one of which is index
.
<div *ngFor="let post of posts; let i=index">
{{ i }}
</div>
Also almost all the punctuation in the syntax are optional. The semi-colon isn't mandatory.
<div *ngFor="let post of posts let i=index let even=even let odd=odd">
{{ i }}
</div>

ruth
- 29,535
- 4
- 30
- 57