我是Angular框架的新手,并且最近已将其介绍给attribute *ngFor=""。
据我了解,它采用与JavaScript for()循环相同的参数...因此,*ngFor="let item of itemCollection"。但是,与其他指令相反,*ngFor它不需要[]将其视为代码。
该文档页面建议该hero属性需要[]围绕该属性,以便将该值视为代码,并返回的值"hero":
<app-hero-detail *ngFor="let hero of heroes" [hero]="hero"></app-hero-detail>
Run Code Online (Sandbox Code Playgroud)
为什么会这样呢?该*ngFor也评估,但不需要[]明显......这是不是*表示,该值必须始终作为代码或者什么被视为前缀?