What is the meaning of * in *ngFor in angular2?

ngFor can only be applied to a <template>. *ngFor is the short form that can be applied to any element and the <template> element is created implicitly behind the scene.

https://angular.io/api/common/NgForOf

Syntax

  • <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>

It’s the same pattern for all structural directives

Plunker example

update

With the 2.0.0 final release <ng-container> was introduced, that behaves like <template> (a wrapper element that isn’t actually added to the DOM) but supports the *ngFor="..." syntax.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)