This is great — but the component is injected as a sibling of HomeComponent.
Gary Dexter
1

Answering my own question, it looks like ViewChild is the key.

Inside the HomeComponent template HTML:

<div #parent></div>

Then, inside the HomeComponent class:

export class HomeComponent {
@ViewChild('parent', {read: ViewContainerRef})
parent: ViewContainerRef;
...

And finally in your sayHello function, change this:

const ref = this.viewContainerRef.createComponent(factory);

To this:

const ref = this.parent.createComponent(factory);

And there you have it. All components are now injected as children of HomeComponent instead of siblings.

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.