I would like to implement an Angular 2 directive that behaves like jQuery's wrapInner
method.
The library I'm writing will use angular 2+ only (no jQuery).
Basically, the directive will take the content of the element or component it has been applied to, and wrap that content in a div (or perhaps wrap it in some other html tag that's passed in as a parameter)
For example,
<myComponent wrapInner>
... All The Content ...
</myComponent>
should result in something like,
<myComponent >
<div class="innerStyles" >
... All The Content ...
</div>
</myComponent>
I am not sure what the most angular-style 'idiomatic' approach to this, as it seems to involves manipulating the DOM which is discouraged.
So could this perhaps be something that is better off being a Structural directive? Or involve manipulating templates
or using ViewContainer
in some way? I dont know how to use those.
However, I have put together a plunker where I use the (discouraged) insecure and inefficient way of going about this; by manipulating DOM through ElementRef
.
Kindly Assist.
I really appreciate it!