Building  Large-Scale Web Applications with Angular
上QQ阅读APP看书,第一时间看更新

Asterisk (*) in structural directives

The * prefix is a terser format to represent a structural directive. Take, for example, the usage of ngFor by the video player. The ngFor template:

<div *ngFor="let video of safeVideoUrls"> 
   <iframe width="198" height="132" [src]="video" frameborder="0" allowfullscreen></iframe> 
</div>

Actually expands to the following:

<ng-template ngFor let-video [ngForOf]="safeVideoUrls">  
<div>
<iframe width="198" height="132" [src]="video" ...></iframe>
</div>
</ng-template>

The ng-template tag is an Angular element that has a declaration for ngFor, a template input variable (video), and a property (ngForOf) that points to the safeVideoUrls array. Both the preceding declarations are a valid usage of ngFor.

Not sure about you, but I prefer the terser first format for ngFor!