Skip to content

feature: ngHost (reverse host projection) #7546

@mhevery

Description

@mhevery

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>)

/cc @jelbourn @tbosch @pkozlowski-opensource

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions