angular - ng2 - Difference between ng-container and ng-template tags -
can please illustrate difference between using <ng-container> , <ng-template> elements?
i not find documentation ngcontainer , don't quite understand difference between template tag.
a code example of each help.
both of them @ moment (2.x, 4.x) used group elements without having introduce element rendered on page (such div or span).
template, however, requires nasty syntax. example,
<li *ngfor="let item of items; let = index; trackby: trackbyfn">...</li> would become
<template ngfor let-item [ngforof]="items" let-i="index" [ngfortrackby]="trackbyfn"> <li>...</li> </template> you can use ng-container instead since follow nice * syntax expect , familiar with.
<ng-container *ngfor="let item of items; let = index; trackby: trackbyfn"> <li>...</li> </ng-container> you can find more details reading this discussion on github.
note in 4.x <template> deprecated , changed <ng-template>.
use
<ng-container>if need helper element nested structural directives*ngifor*ngforor if want wrap more 1 element inside such structural directive;<ng-template>if need view "snippet" want stamp @ various places usingngfortemplate,ngtemplateoutlet, orcreateembeddedview().
Comments
Post a Comment