Is there an Angular 2+ Equivalent to React Fragments?
"ng-container" is an element that’s available in Angular 2+ and that can act as the host to structural directives.
<ng-container>
<div>Foo</div>
<div>Bar</div>
</ng-container>
You can do like this:
@Component({
// tslint:disable-next-line: component-selector
selector: '[my-fragment-component]',
...
})
export class MyFragmentComponent {}
...
<div my-fragment-component>
</div>
It will work, don't know of any possible side-effects...
Usage ng-container
with ngFor
( for ) loop and table tag.
<table>
<thead>
<tr>
<th>ID</th>
<th>Title</th>
</tr>
</thead>
<tbody>
<ng-container *ngFor="let item of items">
<tr>
<td>{{ item.id }}</td>
<td>{{ item.title }}</td>
</tr>
<ng-container>
<tbody>
</table>