I have this
https://angular-dynamic-component-append.stackblitz.io/
I managed to dynamically append an element, but it doesn't get compiled. I saw many tutorials like this
But it's not really what I need. And often they use the hashtag notation to identify the container.
I need to append a component to any element which may have my custom directive on it.
I'd also need to use the bind value of the directive to control a [hidden] attribute on the appended element.
THE GOALS
- Override behaviour of existing component:
- adding an attribute to show/hide
- adding a class to customize appearance
- Reduce html coding
- No need to write the entire component
<my-comp></mycomp> - No need to know the class
- Automatic behaviour if the class name is changed
- Changing the element on which the directive is applied
- The final goal will be to add a class to the contaner element
- No need to write the entire component
Expected source
<div [myDirective]="myBoolean">
<p>some content</p>
</div>
Expected compiled
<div [myDirective]="myBoolean" class="myDirectiveClass1">
<p>some content</p>
<someComponent [hidden]="myBoolean" class="myDirectiveClass2"></someComponent>
</div>
Is there a way to achieve this?
Thank you in advance
<mat-card>so you don't need to do it at all. But if you need to dynamically create an element at runtime without registering it ahead of time, you are hosed.