I am trying to create a component that reuses ion-header
. With the way ion-header
works, it needs to be a root component of the page (contained by nothing except body
). I have looked into a couple of ways to do this:
- Angular 2 - ngfor without wrapping in a container
- Angular2 : render a component without its wrapping tag
I have created a component with an attribute selector:
@Component({
selector: '[head]',
template: `<ion-header>... {{head}} ...</ion-header>`,
})
export class HelloComponent {
@Input() head: string;
}
However, if I try to use <ng-container head="The Title"></ng-container>
I get an error: DOMException: Failed to execute 'appendChild' on 'Node': This node type does not support this method.
from the Angular renderer itself.
I can update the template to include the content of ion-header
itself and instead have <ion-header head="The Title"></ion-header>
, but I would like to be able to reuse the component as a whole rather than having to specify the element and directive. This also prevents me from being able to include other attributes with ion-header
if it's needed.
Example: https://stackblitz.com/edit/angular-fgfudn
Is there any way to render a component's template contents at the root level?