Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Transclude slot doesn't work as expected when outlet is in a <table> #15598

Closed
cheapsteak opened this issue Jan 11, 2017 · 5 comments
Closed

Comments

@cheapsteak
Copy link

cheapsteak commented Jan 11, 2017

Want to create a table component but still allow users to customize the rendering of each row

This does not seem to work

component('myTable', {
    transclude: {
      row: 'row',
    },
    replace: true,
    template: `
      <table>
        <tr ng-repeat="row in vm.rows" ng-transclude="row">
        </tr>
      </table>
    `,
  })
<my-table>
    <row>
        <td>this doesn't show up</td>
    </row>
</my-table>

The <row> tag ends up being rendered inside the <tr>, and <td>s are lost

image

The browser takes liberties with <tr> and <td> tags (seems to strip them out if they're not in the right place)

One way to solve would be if we could transclude <tr attribute-selector> and transclude: { row: '[attribute-selector]'}

@cheapsteak cheapsteak changed the title Transclude slot doesn't work when outlet is in a <table> Transclude slot doesn't work as expected when outlet is in a <table> Jan 11, 2017
@Narretz
Copy link
Contributor

Narretz commented Jan 11, 2017

Looks like this is a follow-up to #14169

Yes, browsers discard td and tr elements if they are not inside a table element. This is standard behavior and cannot be changed, because the browser parses the HTML before Angular mutates the DOM. Looks like a valid use case attribute selectors in multi transclusion.

Css / Complex selectors are tracked here: #14709

Btw you can't use replace in components.

@gkalpak
Copy link
Member

gkalpak commented Jan 11, 2017

I am not sure how attribute selectors would help here. The problem is that you can't have <td> elements inside non-<tr> elements. How you select them is not the issue.

@cheapsteak
Copy link
Author

cheapsteak commented Jan 11, 2017

I think attribute selectors would allow

component('myTable', {
    transclude: {
      row: '[row]',
    },
});
<my-table>
    <tr row>
        <td>content</td>
    </tr>
</my-table>

@gkalpak
Copy link
Member

gkalpak commented Jan 11, 2017

It wouldn't, because <tr> elements are not allowed inside <my-table>.

@Narretz
Copy link
Contributor

Narretz commented Jan 18, 2017

@gkalpak is correct, I think we can close this. Angular 1 is not built to work around these browser limitations.

@Narretz Narretz closed this as completed Jan 18, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants