“..让我=索引”和“..让我作为索引”有什么区别?

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

我是 angular 的新手,我一直在观看一些 YouTube 视频。其中一些使用“let item of items; let i as index”,另一个使用“let item of items; let i = index” .我试图在 google 中搜索它们的区别,但似乎找不到简单的答案。有人能解释一下粗体代码有什么区别吗?谢谢!

只是shorthand(缩小代码),例如这段代码

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

是 shorthand 代码:

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

所以基本上它们是一样的:)

Angular 文档:link

谢谢你回答我的问题。

我还想澄清一下上面的一些事情。你说的只是对方的一个shorthand代码。所以基本上,我尝试了一些东西,这就是我得到的:

来自代码:

 <div class="todo" *ngFor="let list of lists; index as i">

<div class="todo" *ngFor="let list of lists; let i = index">

它们产生相同的结果。但是根据我的问题,我写了

<div class="todo" *ngFor="let list of lists; let i as index">

这将产生一个 [对象]

所以,我假设这段代码:

只是一个错字。

感谢您澄清它们的区别。非常感谢您的帮助!