【发布时间】:2019-11-27 06:07:02
【问题描述】:
当我在父页面中分别为 table 和 thead 和 tbody 创建组件时,表格完全崩溃了。
不知道怎么解决。
表格组件:
<table>
<ng-content></ng-content>
</table>
头组件:
<thead>
<tr>
<th>Someple header</th>
<th>Someple header</th>
</tr>
</thead>
tbody 组件:
<tbody>
<tr>
<td>sample data1</td>
<td>sample data2</td>
</tr>
</tbody>
放在一起时:
<app-table>
<app-thead></app-thead>
<app-tbody></app-tbody>
</app-table>
但它打破了桌子。全部排列为内联元素。如何解决?
【问题讨论】:
-
如果您检查 html 结果,您可以看到:
<body> <my-app> <app-table> <table> <app-thead> <thead>...</thead> </app-thead> <app-tbody> <tbody>...</tbody> </app-tbody> </table> </app-table> </my-app> </body>作为解决方案,我建议您使用 TemplateRef -
@Myugen - 你能分享一个关于 templateRef 的示例或教程吗?在这种情况下如何处理?
-
这个问题在这里解决了:stackoverflow.com/questions/43631813/…
-
@3gwebtrain 与普通的
<table>相比,您究竟想用这个<app-table>实现什么? -
@Taurayi - 通过分别传递标头数组和正文数组创建动态表,并要求保留多个值的转租