I want to generate a component without its wrapper tag. I read all similar SO questions (e.g. SO1, SO2, SO3), without finding a proper solution.
My existing, simplified component (toggle-button.component.ts):
import {Component} from "@angular/core";
@Component({
selector: "toggle-button, [toggleButton]",
template: `<button type="button" class="btn btn-primary">{{ label }}</button>`
})
export class ToggleButtonComponent {
@Input()
public label: string;
}
Second component, which I want to create (select-button.component.ts):
import {Component} from "@angular/core";
@Component({
selector: "select-button",
template: `
<div class="btn-group" role="group">
<ng-container *ngFor="let item of items">
<ng-container toggleButton [label]="item.label"></ng-container>
</ng-container>
</div>
`
})
export class SelectButtonComponent {
@Input()
public items: {label: string; value: any;};
}
My app.component.html
<select-button [items]="items"></select-button>
The result is an error:
Failed to execute 'appendChild' on 'Node': This node type does not support this method.
What I want to achieve is a HTML structure like this:
<div class="btn-group" role="group">
<button type="button" class="btn btn-primary">12 H</button>
<button type="button" class="btn btn-primary">24 H</button>
</div>
Instead of:
<div class="btn-group" role="group">
<toggle-button>
<button type="button" class="btn btn-primary">12 H</button>
</toggle-button>
<toggle-button>
<button type="button" class="btn btn-primary">24 H</button>
</toggle-button>
</div>
Stackblitz link