Last active
April 7, 2019 17:26
-
-
Save arturovt/fb01e065ac4b02432a984af91b6bf3d5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ng-container *ngComponentOutlet="ButtonComponent"></ng-container> | |
<!-- Скомпилированный шаблон --> | |
<ng-template [ngComponentOutlet]="ButtonComponent"> | |
<!-- Неиспользуемый `ng-container` --> | |
<ng-container></ng-container> | |
</ng-template> | |
<!-- Гораздо лучше, нет неиспользуемого контейнера --> | |
<ng-template [ngComponentOutlet]="ButtonComponent"></ng-template> | |
<!-- Еще пример --> | |
<ng-container *ngIf="interval$ | async as counter"> | |
<p>{{ counter }}</p> | |
</ng-container> | |
<!-- Скомпилированный шаблон --> | |
<ng-template [ngIf]="interval$ | async" let-counter> | |
<ng-container> | |
<p>{{ counter }}</p> | |
</ng-container> | |
</ng-template> | |
<!-- | |
Так намного лучше, нет неиспользуемого `ng-container` | |
--> | |
<ng-template [ngIf]="interval$ | async" let-counter> | |
<p>{{ counter }}</p> | |
</ng-template> | |
<!-- Еще пример --> | |
<ng-container *ngFor="let item of object | keyvalue"> | |
<app-product *ngFor="let product of item.value" [product]="product"></app-product> | |
</ng-container> | |
<!-- | |
Скомпилируется в данную структуру, то есть мы получим | |
`(object | keyvalue).length` элементов `ng-container` | |
--> | |
<ng-template ngFor [ngForOf]="object | keyvalue" let-item> | |
<ng-container> | |
<ng-template ngFor [ngForOf]="item.value" let-product> | |
<app-product [product]="product"></app-product> | |
</ng-template> | |
</ng-container> | |
</ng-template> | |
<!-- Так намного лучше, не нужен неиспользуемый `ng-container` --> | |
<ng-template ngFor [ngForOf]="object | keyvalue" let-item> | |
<app-product *ngFor="let product of item.value" [product]="product"></app-product> | |
</ng-template> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment