以下示例中的ngFor之前的*是什么意思,为什么需要它?
<div *ngFor="#hero of heroes" (click)="selectHero(hero)">
{{hero.name}}
</div>
ngFor
只能应用于<template>
。*ngFor
是可应用于任何元素的简短形式,并且该<template>
元素是在后台隐式创建的。
https://angular.io/api/common/NgForOf
句法
<li *ngFor="let item of items; let i = index">...</li>
<li template="ngFor let item of items; let i = index">...</li>
<template ngFor let-item [ngForOf]="items" let-i="index"><li>...</li>
所有结构指令的模式都相同
更新
在2.0.0版<ng-container>
中引入了最终版本,其行为类似于<template>
(实际上未添加到DOM中的包装元素)但支持*ngFor="..."
语法。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句