-
Notifications
You must be signed in to change notification settings - Fork 26.6k
Closed
Labels
Description
At times it is desirable to be able to wrap a host element into a template. (We may refer to it as host projection, to be consistent with content projection)
The idea is that we would allow the component's view to declare <ng-host>
which would project the host element in similar fashion to the <ng-content>
projection
Imagine we have template:
<menu>
<menu-item>A</menu-item>
<menu-item>B</menu-item>
</menu>
and we want
<menu>
<ul>
<li><menu-item>A</menu-item></li>
<li><menu-item>B</menu-item></li>
</ul>
</menue>
Here the <menu>
can have <ul>
, but how do we wrap <menu-item>
in <li>
?
@Component({
selector: 'menu-item',
template: '<li><ng-host></ng-host></li>'
})
class MenuItem {...}
Notes:
<ng-host>
could have optional attribute to suppress the host element, this way it will be<li>A</li>
(remove<menu-item>
)