What is the difference between ngFor and * ngFor

I cannot find a good description of the differences anywhere. Same thing with *ngIfandngIf

Example *ngFor

<li *ngFor="let video of page" ...>
  <img src="api/Videos/{{video.id}}/thumbnail">
</li>

and example ngFor

<template ngFor let-labelid [ngForOf]="labelLookup | keyValueFilter" >
  <label  [ngStyle]="{'background-color': labelLookup[labelid].color}">
    <input (click)="changeLabel(labelid)" type="radio" name="labelSelector" value="{{ labelid }}" [checked]="labelid == 1">
  </label>
</template>
+4
source share
1 answer

The difference is that *ngForinternally converted to <template ngFor [ngForOf]="...".

They are equivalent, but the first is more convenient to write.

The explicit version ( <template ngFor ...>) allows you to apply the directive to several elements at once, while the implicit version (shorthand) only wraps the element to which it is applied with a tag <template>.

Angular 2.0.0 <ng-container>, , <template> ( DOM).

.

+4

Source: https://habr.com/ru/post/1658359/


All Articles