Consider a scenario where I have a parent and child component in Angular 12. Their templates are structured as follows:
Parent:
<h1>This is the parent component</h1>
<div class="container">
<div class="row">
<div class="col">Foo</div>
<ng-container>
<app-child-component></app-child-component>
</ng-container>
</div>
</div>
Note: ng-container must be used.
Child:
<button>Click</button>
Angular creates a wrapper around the child component template, resulting in:
<h1>This is the parent component</h1>
<div class="container">
<div class="row">
<div class="col">Foo</div>
<app-child-component>
<button>Click</button>
</app-child-component>
</div>
</div>
The desired layout I aim to achieve is:
<h1>This is the parent component</h1>
<div class="container">
<div class="row">
<div class="col">Foo</div>
<button>Click</button>
</div>
</div>
I attempted using an attribute selector, like so:
<div app-child-component></div>
Unfortunately, this approach adds an unnecessary div element. Attribute selectors cannot be applied to elements like ng-template.