Update:
The correct question is probably: "how do I implement my own version of ng-container
so I can use "<my-component ...>...</my-component>
" instead of "<ng-container my-directive ...>...</ng-container>
".
I am developing a new app in Angular 4. I want to build my entire app with wrapper components so I can swap out the actual components if need be. This works easily for simple controls but not for complex controls we want to break up into separate components. The best example is with tabs because the requirements are fairly stable: a list of tabs with labels and content panels that we show/hide.
ng-bootstrap may use something like this:
<ngb-tabset>
<ngb-tab title="Tab 1">
<ng-template ngbTabContent>...</ng-template>
</ngb-tab>
...
<ngb-tabset>
We may have some other component like this:
<div class="my-tab-group">
<ul>
<li>Tab 1</li>
...
</ul>
<div class="my-tab" title="Tab 1">...</div>
...
</div>
Instead of tying my app to a specific implementation at this time I want to define my own tabs wrapper and use it everywhere like this:
<my-tabs-control>
<my-tab-control title="Tab 1">...</my-tab-control>
...
<my-tabs-control>
Then if I need to change the way my tabs work it happens in one place. However, if we use a wrapper component then the HTML gets polluted with the host element tags interlaced with the desired tags which obviously messes things up, e.g.
<my-tabs-control>
<div class="my-tab-group">
<ul>
<li>Tab 1</li>
...
</ul>
<my-tab-control title="Tab 1">
<div class="my-tab" title="Tab 1">...</div>
</my-tab-control>
...
</div>
<my-tabs-control>
My guess is this is the reason why a lot of people ask how to unwrap/remove the host element in an Angular component - that would make this really simple to do.
The usual answer is to use attribute selectors instead, e.g.:
Remove the angular2 component's selector tag
How to remove/replace the angular2 component's selector tag from HTML
However, this means we need to know the tag structure at the usage site, which obviously destroys the whole point of using nicely named wrapper tags.
Thus, finally, how should I be doing this? Is it perhaps not possible due to performance reasons? I have started looking at Renderer2 but have not found an obvious way to do what I want, and I want to avoid non-angular DOM hacks.