Angular 2 component without selector tag in DOM
To answer your question, you can also do this...
@Component({
selector: '[my-component]'...
<my-component *ngIf="..."</my-component>
// becomes this in the dom
<div my-component _nghost...>
There is also ng-container for this purpose.
<ng-container *ngIf="something.is.there">
<div class="here">
Hello
</div>
</ng-container>
// DOM: => <div class="here">Hello</div>
Use equivalent expanded *ngIf
notation with template
tag:
<template [ngIf]="check">
<div>div 1...</div>
<div>div 2...</div>
<div>div 3...</div>
</template>
You can solve this by using CSS only, just set my-component
as display: contents
,
my-component {
display: contents;
}
As stated on display: contents
documentation, this causes to appear as if the component were direct children of the element's parent.