Home > other >  What is the difference of ".. let i = index" and "..let i as index"?
What is the difference of ".. let i = index" and "..let i as index"?

Time:04-01

I am new to angular and I've been watching some youtube videos. Some of them use "let item of items; let i as index" and another one use "let item of items; let i = index". I tried to search for their difference in google, but I can't seem to find a simple answer. Can somebody explain what's the difference of the bolded codes? Thank you!

CodePudding user response:

It's just shorthand(minified code), for example this code

<li *ngFor="let item of items; index as i; trackBy: trackByFn">...</li>

is shorthand code for this:

<ng-template ngFor let-item [ngForOf]="items" let-i="index" [ngForTrackBy]="trackByFn">
  <li>...</li>
</ng-template>

So baiscally the are the same :)

Angular Docs :

  • ...
  • " rel="nofollow noreferrer">link

    • Related