Skip to content

Feature: Hostless components #18877

Open
Open

Description

@MickL

I'm submitting a...


[ ] Regression
[ ] Bug report
[X] Feature request
[ ] Documentation issue or request
[ ] Support request

Current behavior

Component-containers like <app-root>, <app-hero-list>, etc. do break flex layout.

Expected behavior

A component(or whole module) should have the option to create no html-element. Instead Angular should work with comments instead of html-elements, exactly like ng-container.

Minimal reproduction of the problem with instructions

<html style="width: 100%; height: 100%;">
   <body style="width: 100%; height: 100%; display: flex; flex-direction: column;">
      <app-root>
            <div style="flex: 1; background: lightcoral;">I should have full height!</div>
      </app-root>
   </body>
</html>

Plunker: https://plnkr.co/edit/aOWUciRx2EsRsKwL2zma?p=preview
(Uncomment app-root in styles.css to see currently needed fix)

What is the motivation / use case for changing the behavior?

Using display:flex only affects the child-element which gets broken by any <app-component> tag. To apply the example above with multiple nested components to require ugly, hardcoded stylesheets:

   body,
   app-root,
   app-hero,
   app-hero-list,
   app-hero-detail {
       display: flex;
       flex-direction: column;
  }

Also, as a frontend developer, i don't like the <app-component> tags either :D

Environment


Angular version: 4.x.x / 5.x.x

Activity

  1. ericmartinezr commented on Aug 25, 2017

    @ericmartinezr
    Contributor
  2. MickL commented on Aug 25, 2017

    @MickL
    Author

    This is a totally different framework. I just want to not break the cascade. If i would create the app with plain html an js there would be no unnecessary containers, too.

  3. mlc-mlapis commented on Aug 25, 2017

    @mlc-mlapis
    Contributor

    @MickL ... <ng-container> and <ng-template> work with comments. Also attribute components like my-columns in <tr my-columns></tr>.

    If I understand you suggest to Angular does the same for any place, any component, ... and so on.

  4. trotyl commented on Aug 25, 2017

    @trotyl
    Contributor

    It would be impossible to keep consistency between ViewEncapsulation.Native and ViewEncapsulation.Emulated, since comment cannot have shadow root.

  5. MickL commented on Aug 25, 2017

    @MickL
    Author

    At least :host would not work anymore. Styles could be generated into global css instead.

    @mlc-mlapis Im not sure if you understand me right. I wish for replacing component-containers like <app-name>name works!</app-name> with <!--<app-name>-->name works!<!--</app-name>--> to create no dom-element for the component itself.

  6. mlc-mlapis commented on Aug 25, 2017

    @mlc-mlapis
    Contributor

    @MickL ... yes, I understand what you want, just wanted to be sure. You came probably from another world ... :host would not work, ... all is moving from global scope to an encapsulated form (Emulated or Native) and you go opposite? And also replacing component-containers ... when general custom components concept is under heavy development?

  7. MickL commented on Aug 25, 2017

    @MickL
    Author

    I do work with Angular a lot and like css encapsulation. It was just an idea to make non-visible-component-containers possible because they disturb. If shadow dom is not possible with comment-containers then screw it, comment-containers may be more important because css will not work correctly anyway.

  8. MickL commented on Aug 29, 2017

    @MickL
    Author

    The expected behavior is exactly the same as ng-container

  9. added
    area: core
    on Sep 20, 2017
  10. added
    feature
    on Oct 27, 2017
  11. staeke commented on Nov 30, 2017

    @staeke

    With a solution to this, I believe you're right @mlc-mlapis - :host and Shadow DOM could probably not work. However, when you want something like this - I guess you don't care about Shadow DOM, and :host shouldn't really apply either. You want HTML "tightness" when, in fact, components produce html that belongs to the same "css system".

    I guess the case that seems hard (impossible?) to accomplish with angular is

    <table>
    <tbody>
      <some-rows-component></some-rows-component> <!-- Produces a couple of <tr>s -->
      <some-other-rows-component></some-other-rows-component>
    </tbody>
    </table>

    EDIT:
    One way to do it is

    class NoRootTagComponent implements OnInit {
        @ViewChild(TemplateRef) template;
    
        constructor(private vcRef:ViewContainerRef) {}
    
        ngOnInit() {
            this.vcRef.createEmbeddedView(this.template);
        }
    }
    
    @Component({
      template: `<ng-template>
    <tr>...</tr>
    <tr>...</tr>
    </ng-template>`
    })
    class SomeRowsComponent extends NoRootTagComponent {
       constructor(vcRef:ViewContainerRef) {
            super(vcRef);
        }
    }
  12. mlc-mlapis commented on Nov 30, 2017

    @mlc-mlapis
    Contributor

    @staeke ... and what about to use attribute components like:

    <table>
    <tbody>
      <tr some-rows-component></tr>
      <tr some-other-rows-component></tr>
    </tbody>
    </table>
    
  13. staeke commented on Nov 30, 2017

    @staeke

    Well @mlc-mlapis, you’d get trs within trs

  14. mlc-mlapis commented on Nov 30, 2017

    @mlc-mlapis
    Contributor

    @staeke ... ah, I thought about it from a wrong side. My mistake.

  15. smnbbrv commented on Jan 7, 2018

    @smnbbrv

    @staeke does not work as is for me because the OnInit does not capture the templateRef. However adding a hash-variable on ng-template + reading it by name works fine:

    <ng-template #template-ref>asd</ng-template>
    @ViewChild('template-ref') template;
  16. 104 remaining items

  17. hungtcs commented on Sep 25, 2025

    @hungtcs

    I believe the host element is actually part of Angular’s charm. It makes an Angular component look like a real element rather than just a piece of template logic. Many important Angular features are also tied to the host element.
    So far, I haven’t seen any functionality that truly requires removing the host element in order to be achieved.

    You can always use the :host selector to style the wrapper directly, instead of repeatedly defining a custom wrapper element inside the component.

    @Component({
      selector: 'app-root',
      template: `I should have full height!`,
      styles: `
        :host{  
          flex: 1; 
          background: lightcoral;
        }
      `,
    })
    export class Playground {
    
    }
    <html style="width: 100%; height: 100%;">
      <body style="width: 100%; height: 100%; display: flex; flex-direction: column;">
        <app-root _nghost-ng-c3984273398="">I should have full height!</app-root>
      </body>
    </html>
  18. leoncik commented on Sep 25, 2025

    @leoncik

    I believe the host element is actually part of Angular’s charm. It makes an Angular component look like a real element rather than just a piece of template logic. Many important Angular features are also tied to the host element. So far, I haven’t seen any functionality that truly requires removing the host element in order to be achieved.

    There are valid cases where the host element becomes more of a liability than a feature:

    Invalid or broken semantics

    In certain elements (like <table>, <tr>, <ul>, <select>), inserting a wrapper tag results in HTML that’s technically invalid.

    Browsers usually try to “fix” this automatically, but it can cause cross-browser quirks, accessibility issues, or break expectations for assistive technologies.

    Debugging & maintainability

    Wrapping elements makes the DOM harder to read.

    Consider this simple custom table:

    <main>
        <app-table _nghost-ng-c4098229708=""
            ><table _ngcontent-ng-c4098229708="">
                <app-table-head
                    _ngcontent-ng-c4098229708=""
                    _nghost-ng-c167012404=""
                    ><thead _ngcontent-ng-c167012404="">
                        <tr _ngcontent-ng-c167012404="">
                            <th _ngcontent-ng-c167012404="" scope="col">
                                Employee Name
                            </th>
                            <th _ngcontent-ng-c167012404="" scope="col">
                                Department
                            </th>
                            <th _ngcontent-ng-c167012404="" scope="col">Project</th>
                            <th _ngcontent-ng-c167012404="" scope="col">
                                Hours/Week
                            </th>
                            <!--bindings={
      "ng-reflect-ng-for-of": "[object Object],[object Object"
    }-->
                        </tr>
                    </thead></app-table-head
                ><app-table-body
                    _ngcontent-ng-c4098229708=""
                    _nghost-ng-c775862262=""
                    ><tbody _ngcontent-ng-c775862262="">
                        <app-table-row
                            _ngcontent-ng-c775862262=""
                            app-table-row=""
                            ng-reflect-employee="[object Object]"
                            ><td>Employee 1</td>
                            <td>Engineering</td>
                            <td>Website Redesign</td>
                            <td>21</td></app-table-row
                        ><app-table-row
                            _ngcontent-ng-c775862262=""
                            app-table-row=""
                            ng-reflect-employee="[object Object]"
                            ><td>Employee 2</td>
                            <td>Design</td>
                            <td>Q4 Sales</td>
                            <td>30</td></app-table-row
                        ><app-table-row
                            _ngcontent-ng-c775862262=""
                            app-table-row=""
                            ng-reflect-employee="[object Object]"
                            ><td>Employee 3</td>
                            <td>Engineering</td>
                            <td>Mobile App</td>
                            <td>37</td></app-table-row
                        ><!--bindings={
      "ng-reflect-ng-for-of": "[object Object],[object Object"
    }-->
                    </tbody></app-table-body
                ><app-table-footer
                    _ngcontent-ng-c4098229708=""
                    _nghost-ng-c2143765403=""
                    ><tfoot _ngcontent-ng-c2143765403="">
                        <tr _ngcontent-ng-c2143765403="">
                            <th
                                _ngcontent-ng-c2143765403=""
                                scope="row"
                                colspan="3"
                            >
                                Total Weekly Hours
                            </th>
                            <td _ngcontent-ng-c2143765403="">75</td>
                        </tr>
                    </tfoot></app-table-footer
                >
            </table></app-table
        >
    </main>

    The same table without extra-markup (and attributes) should be rendered like that:

    <main>
        <table>
            <thead>
                <tr>
                    <th scope="col">Employee Name</th>
                    <th scope="col">Department</th>
                    <th scope="col">Project</th>
                    <th scope="col">Hours/Week</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td>Employee 1</td>
                    <td>Engineering</td>
                    <td>Website Redesign</td>
                    <td>21</td>
                </tr>
                <tr>
                    <td>Employee 2</td>
                    <td>Design</td>
                    <td>Q4 Sales</td>
                    <td>30</td>
                </tr>
                <tr>
                    <td>Employee 3</td>
                    <td>Engineering</td>
                    <td>Mobile App</td>
                    <td>37</td>
                </tr>
            </tbody>
            <tfoot>
                <tr>
                    <th scope="row" colspan="3">Total Weekly Hours</th>
                    <td>75</td>
                </tr>
            </tfoot>
        </table>
    </main>

    Styling issues

    In many scenarios, adding extra wrapping elements when they are not needed can make styling more difficult. You may for example have to drill through twice as many elements when you want to set an element to have a 100% height or apply inheritance rules with subgrid.

    Performance & rendering overhead

    Every extra wrapper is an extra DOM node: more memory consumption, more work for the browser when calculating layout, style, and paint.

    On large tables or deeply nested components, the accumulated overhead can be significant, especially on mobile devices.

    Now, on the suggestions about this issue:

    Option 1: curly braces

    By default, all Angular components should be rendered without the selector tag wrapper. An option could be provided as fallback for backward compatibility, like adding curly braces in the selector to display the wrapping tag:

    import { Component } from '@angular/core';
    
    @Component({
      selector: '{app-fallback-example}',
      templateUrl: './fallback-example.component.html',
      styleUrls: ['./fallback-example.component.css'],
    })
    export class FallbackExampleComponent {}

    Option 2: Host configuration

    For the other way around, (an opt-in mechanism to render a component without its host wrapper), Angular could extend the host configuration:

    import { Component } from '@angular/core';
    
    @Component({
      selector: 'app-title',
      template: `<h1>Main title</h1>`,
      styles: [`h1 { font-size: 2rem; }`],
      host: { element: 'none' },
    })
    export class TitleComponent {}

    Option 3: New encapsulation mode

    Another possibility would be to introduce a new ViewEncapsulation option, e.g. Hostless, that indicates Angular should not render a host wrapper for this component:

    import { Component, ViewEncapsulation } from '@angular/core';
    
    @Component({
      selector: 'app-title',
      template: `<h1>Main title</h1>`,
      encapsulation: ViewEncapsulation.Hostless,
    })
    export class TitleComponent {}
  19. hungtcs commented on Sep 25, 2025

    @hungtcs

    I believe the host element is actually part of Angular’s charm. It makes an Angular component look like a real element rather than just a piece of template logic. Many important Angular features are also tied to the host element. So far, I haven’t seen any functionality that truly requires removing the host element in order to be achieved.

    There are valid cases where the host element becomes more of a liability than a feature:

    Invalid or broken semantics

    In certain elements (like <table>, <tr>, <ul>, <select>), inserting a wrapper tag results in HTML that’s technically invalid.

    Browsers usually try to “fix” this automatically, but it can cause cross-browser quirks, accessibility issues, or break expectations for assistive technologies.

    Debugging & maintainability

    Wrapping elements makes the DOM harder to read.

    Consider this simple custom table:

    Employee Name Department Project Hours/Week
    Employee 1 Engineering Website Redesign 21Employee 2 Design Q4 Sales 30Employee 3 Engineering Mobile App 37
    Total Weekly Hours 75
    The same table without extra-markup (and attributes) should be rendered like that:
    Employee Name Department Project Hours/Week
    Employee 1 Engineering Website Redesign 21
    Employee 2 Design Q4 Sales 30
    Employee 3 Engineering Mobile App 37
    Total Weekly Hours 75
    ## Styling issues In many scenarios, adding extra wrapping elements when they are not needed can make styling more difficult. You may for example have to drill through twice as many elements when you want to set an element to have a 100% height or apply inheritance rules with subgrid.

    Performance & rendering overhead

    Every extra wrapper is an extra DOM node: more memory consumption, more work for the browser when calculating layout, style, and paint.

    On large tables or deeply nested components, the accumulated overhead can be significant, especially on mobile devices.

    Now, on the suggestions about this issue:

    Option 1: curly braces

    By default, all Angular components should be rendered without the selector tag wrapper. An option could be provided as fallback for backward compatibility, like adding curly braces in the selector to display the wrapping tag:

    import { Component } from '@angular/core';

    @component({
    selector: '{app-fallback-example}',
    templateUrl: './fallback-example.component.html',
    styleUrls: ['./fallback-example.component.css'],
    })
    export class FallbackExampleComponent {}

    Option 2: Host configuration

    For the other way around, (an opt-in mechanism to render a component without its host wrapper), Angular could extend the host configuration:

    import { Component } from '@angular/core';

    @component({
    selector: 'app-title',
    template: <h1>Main title</h1>,
    styles: [h1 { font-size: 2rem; }],
    host: { element: 'none' },
    })
    export class TitleComponent {}

    Option 3: New encapsulation mode

    Another possibility would be to introduce a new ViewEncapsulation option, e.g. Hostless, that indicates Angular should not render a host wrapper for this component:

    import { Component, ViewEncapsulation } from '@angular/core';

    @component({
    selector: 'app-title',
    template: <h1>Main title</h1>,
    encapsulation: ViewEncapsulation.Hostless,
    })
    export class TitleComponent {}

    Actually https://material.angular.dev/components/table/overview has provided a good solution, the angular component supports multiple types of selectors.

    @Component({
      selector: 'td[app-table-cell],th[app-table-cell]',
      template: `
        Cell content
      `,
    })
    export class TableCellComponent {}
    
    @Component({
      selector: 'thead[app-table-head]',
      template: `
        <ng-content></ng-content>
      `,
    })
    export class TableHeadComponent {}
    
    @Component({
      selector: 'app-root',
      template: `
        <table>
          <thead app-table-head>
            <tr>
              <th app-table-cell></th>
              <th app-table-cell></th>
              <th app-table-cell></th>
            </tr>
          </thead>
          <tbody>
            <tr>
              <td app-table-cell></td>
              <td app-table-cell></td>
              <td app-table-cell></td>
            </tr>
          </tbody>
        </table>
      `,
      imports: [TableHeadComponent, TableCellComponent],
    })
    export class App {}
  20. leoncik commented on Sep 25, 2025

    @leoncik

    You are referring to attribute selector, right? They do indeed remove the wrapping tag but this causes a styling issue: the styling can no longer be encapsulated inside the component, part of the styles must be moved to the parent component.

    In your example, the styles of the cell can’t be set in the TableCellComponent, they have to be moved up to the App component, which is not viable to create a reusable component.

  21. davidbusuttil commented on Sep 25, 2025

    @davidbusuttil

    You could in theory do element tag + class name: "[p.paragraph]" as an example. Any <p class="paragraph"></p> would be a valid component. But this approach has a huge pitfall: namespaces.

    If you try this approach with an SVG element, the children (paths, etc) would not be rendered properly as the namespace for this would be http://www.w3.org/2000/svg.

  22. davidbusuttil commented on Sep 25, 2025

    @davidbusuttil

    I believe the host element is actually part of Angular’s charm. It makes an Angular component look like a real element rather than just a piece of template logic. Many important Angular features are also tied to the host element. So far, I haven’t seen any functionality that truly requires removing the host element in order to be achieved.

    You can always use the :host selector to style the wrapper directly, instead of repeatedly defining a custom wrapper element inside the component.

    @component({
    selector: 'app-root',
    template: I should have full height!,
    styles: :host{ flex: 1; background: lightcoral; },
    })
    export class Playground {

    }

    I should have full height!

    There is a very valid use case: CMS based on JSON. Nuxt.js offers a CMS based on Markdown. I have managed to build one using Angular, however, I had to resort to ViewContainerRef's createComponent using HTML element tag + class names as selectors. The big caveat was with SVG elements, as the createComponent thereof does not allow to specify the name space of the created Angular element.

  23. mauriziocescon commented on Sep 25, 2025

    @mauriziocescon

    I'm so happy this point is back on the agenda: hooray! 🎉🥁🔝

    That said, to me the most difficult part is defining common ground around the meaning of "hostless components," which for me is not limited to "avoiding extra HTML tags", "tailwind class conflicts" etc. (all absolutely legitimate). As I see it, hostless components also imply fixing the following problems:

    1. components have selectors and hosts;
    2. you cannot easily pass markup — an ng-template — as an input to be rendered (type-safely and easily);
    3. you cannot pass behaviors (attribute directives) as inputs and attach them to DOM elements;
    4. you cannot "spread props."

    These points make "template composition" like in React / Vue / Svelte impossible in Angular today (for reference, see #54782 (comment)).

    As a consequence, directives (of any nature) are the primary "template composition" tool. But they are complex to use, specific to Angular, and introduce mental overhead along with other problems. As I see it, hostless components would more or less fix the entire template composition issue and align Angular with the industry. Attribute directives would then have a more scoped role.

    There's no disagreement that this would be a huge (and multiyear) change compared to the current way of doing things. But I think it's the right move, because it would make Angular templates fully declarative, compositional, and inputs-driven without compromises. And improve type safety.

    Conclusion

    I really hope hostless components will be considered in the near future. But as I see it, "hostless" doesn't just mean introducing a component flag for host (yes / no). It has profound implications for:

    • authoring reusable components (libraries);
    • wrapping components / elements (vs. the current directives-driven approach);
    • and DI (template composition driven by inputs and always explicit).

    Cheers!

    ☮️☮️☮️

  24. hungtcs commented on Sep 26, 2025

    @hungtcs

    You are referring to attribute selector, right? They do indeed remove the wrapping tag but this causes a styling issue: the styling can no longer be encapsulated inside the component, part of the styles must be moved to the parent component.

    In your example, the styles of the cell can’t be set in the TableCellComponent, they have to be moved up to the App component, which is not viable to create a reusable component.

    Setting styles inside the component is completely fine.

    @Component({
      selector: 'td[app-table-cell],th[app-table-cell]',
      template: `
        Cell content
      `,
      styles: [
        `
        :host(th) {
          background-color: red;
        }
        :host(td) {
          background-color: green;
        }
        `,
      ],
    })
    export class TableCellComponent {}
    <th app-table-cell="" _nghost-ng-c3047767540=""> Cell content </th>
    <td app-table-cell="" _nghost-ng-c3047767540=""> Cell content </td>
    th[_nghost-ng-c3047767540] {
      background-color: red;
    }
    td[_nghost-ng-c3047767540] {
      background-color: green;
    }
  25. davidbusuttil commented on Dec 22, 2025

    @davidbusuttil

    Hello!

    I suggest this way forward:

    1. create a property called hostless for migration;
    2. require a single root node in the template (more on fragments below) - this will allow all the logic of the host to be attached here;
    3. encapsulation occurs on the root node;
    4. if fragments are needed (i.e. more than 1 root node), create something like <ng-fragment> & </ng-fragment> to encapsulate the view - however, this poses a problem for CSS encapsulation as comments do not allow this, although the root nodes could all share the same host ID and share the CSS styling.
  26. davidbusuttil commented on Dec 22, 2025

    @davidbusuttil

    Hello!

    I suggest this way forward:

    1. create a property called hostless for migration;
    2. require a single root node in the template (more on fragments below) - this will allow all the logic of the host to be attached here;
    3. encapsulation occurs on the root node;
    4. if fragments are needed (i.e. more than 1 root node), create something like <ng-fragment> & </ng-fragment> to encapsulate the view - however, this poses a problem for CSS encapsulation as comments do not allow this, although the root nodes could all share the same host ID and share the CSS styling.

    Nevermind - saw that selectorless components are on the road map - me likey. Waiting for the RFC as I've got tonnes of input!

  27. R-Bower commented on Apr 3, 2026

    @R-Bower

    Nevermind - saw that selectorless components are on the road map - me likey. Waiting for the RFC as I've got tonnes of input!

    They were, but they've recently been removed.

    It was the first item on the v20 docs

    But it's no where to be found on the v21 (current) or next roadmap

  28. davidbusuttil commented on Apr 3, 2026

    @davidbusuttil
  29. dwilches commented on Apr 3, 2026

    @dwilches

    @R-Bower @davidbusuttil I know this is not a full replacement, but you can add this to your component, so its tag doesn't get in the way of CSS styles:

    selector: ...
    template: ...
    host: { style: "display: contents;" }
    
  30. davidbusuttil commented on Apr 3, 2026

    @davidbusuttil

    @R-Bower @davidbusuttil I know this is not a full replacement, but you can add this to your component, so its tag doesn't get in the way of CSS styles:

    selector: ...
    template: ...
    host: { style: "display: contents;" }
    

    The problem is the selector itself. Cannot build a proper dynamic UI library. Also bear in mind correct HTML syntax.

    <ui-list>
      <ul>
        <ui-list-item>
          <li>...</li>
          ...
        </ui-list-item>
      </ul>
    </ui-list>
    

    ❌

    You may mention to use selectors such as [uiList], but that breaks when using ViewContainerRef.createComponent(), with an <ng-component> being inserted.

    I will miss Angular.

  31. mauriziocescon commented on Sep 25, 2026

    @mauriziocescon

    ⚠️ Disclaimer: This idea may well be flawed, or outright impossible to implement. It's mostly how I'd like the mechanism to work, not a claim that it can be built.


    At a high level, I think this is more or less what I'd like a selectorless / hostless implementation to look like:

    1. components and directives are referenced directly by their class in templates (<MyComp @MyDir(...) />),
    2. by default, the host of every component is an ng-container (or something similar in spirit like ng-host),
    3. a component can be marked as having a single root node; in that case, that root node must be a valid and unique element tag, it cannot be wrapped in @if or any other control flow, and it takes over the role of the host for all the host machinery (:host {}, host: {}, hostDirectives: [], @HostBinding, providers: [], ...),
    4. the component boundary is closed, except for inputs, outputs and directives,
    5. styles remain view-scoped, as they are today; the single root node can be styled directly, but only from the inside,
    6. the same principle applies to every other DOM attribute or property (as in the previous point),
    7. CSS custom properties get special treatment on components marked as having a single root node (<MyComp --my-background="color()" />),
    8. class and style on element tags (as opposed to components) behave as they do today: they accept the sugared forms ([class.foo], [style.width], ...), including multiple bindings on the same tag.

    Here are a few examples to better visualize the idea:

    import { ClassValue, cn } from 'cn';
    
    // host = button
    
    @Component({
      rootElement: true,
      template: `
        <button [class]="merged()" (click)="onClick.emit()">
          <ng-content />
        </button>
      `,
      host: {}, // mostly useless (you can work directly on the button), but harmless because it is internal
      hostDirectives: [], // still exposes directives, inputs and outputs to consumers; they are applied to the button
    })
    export class Button {
      readonly class = input<ClassValue>('');
      readonly onClick = output<void>();
    
      // in this case, Button accepts any class
      protected readonly TAILWIND_BTN_DEFAULTS = `...`;
      protected readonly merged = computed(() => cn([this.TAILWIND_BTN_DEFAULTS, this.class()]));
    }
    // host = tr
    
    @Component({
      rootElement: true,
      template: `
        <!-- Tooltip is applied to the host and can use TableRow's inputs -->
        <tr class="..." @Tooltip(...)>
          <td><!-- whatever makes sense --></td>
        </tr>
      `,
      styles: ``, // :host is no longer needed
    })
    export class TableRow {}
    // host = ng-container
    
    @Component({
      template: `
        <!-- whatever makes sense -->
      `,
    })
    export class MultiHtmlTags {}
    // host = ng-container
    
    @Component({
      template: `
        <MultiHtmlTags />
      `,
    })
    export class Wrapper {}
    // host = ng-container
    
    @Component({
      template: `
        <!-- you can only pass inputs, outputs and directives -->
        <!-- Tooltip is applied to the internal button -->
        <Button @Tooltip(...) (onClick)="..." [class]="...">
          Click me!
        </Button>
    
        <table>
          <tbody>
            <TableRow />
          </tbody>
        </table>
    
        <MultiHtmlTags />
        <Wrapper />
      `,
    })
    export class Consumer {}

    Pros

    • likely a simpler mental model, with clear boundaries between components, clear ownership, and a clear data flow,
    • no double imports, no selectors,
    • better template type checking,
    • pipes can be partially represented by components that wrap a single computation, such as template: {{ computation() }},
    • for components marked as having a single root node, host directives can be applied directly to that root node and can depend on the component's inputs,
    • ng-container host components naturally "reject" directives coming from outside the boundary that expect a real element tag (rootElement: true works as a voluntary opt-in),
    • potentially, the root node could be used to type-check directive compatibility, assuming directives can declare which host types they may be attached to.

    Cons

    • a change in the mental model,
    • integrating selector-based components would still require a shared host (<MatButton:a ...>...</MatButton:a>),
    • a single Button cannot target both a button and an a tag at the same time (although there are ways to achieve it, see svelte:element),
    • some things might require adaptations (FormField, for example),
    • some concepts might not be supported at all.

    Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: corecore: host and host bindingsfeaturefeature: under consideration

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions