0

container-component.ts

export class ContainerComponent{
    innerComponentRef; //We have this
    innerComponentSelector;//We have this
    }

However in container-component.html I don't know how to append html with innerComponent tag. String interpolation - doesn't work for sure. I also wonder if it's not a kinda bad practice what I want to make.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Michał Lis
  • 461
  • 1
  • 6
  • 19
  • are you on about custom components? – mast3rd3mon Feb 16 '18 at 16:10
  • Yes, created by me. – Michał Lis Feb 16 '18 at 16:13
  • This isn't how the framework works. Component metadata isn't available to a developer. You will need to maintain a map of components in order to match them by selector or other string, e.g. https://stackoverflow.com/a/40063568/3731501 or https://stackoverflow.com/a/48825228/3731501 – Estus Flask Feb 16 '18 at 16:35

1 Answers1

-1

If you register the components within the declarations: [] in the NgModule, you can do the following in the container-component.html:

<div>
    <innerComponentRef></innerComponentRef>
    <innerComponentSelector></innerComponentSelector>
</div>

Changing innerComponentRef and innerComponentSelector for the selector: "" names

mast3rd3mon
  • 8,229
  • 2
  • 22
  • 46
  • Consider innerComponentRef and innerComponentSelector as variables known only in typescript. InnerComponentSelector can be 'app-inner-1' or 'app-inner-2' or whatever else. That's the problem. I also was wondering about some *ngFor looping all defined components and taking only this one which selector==innerComponentSelector. – Michał Lis Feb 16 '18 at 16:23