[英]In Angular2+, how can I replace a <tr> with my own component without interfering with the dom structure/css
Consider the following table snippet with a rows of people and their result on a test: 考虑下面的表格片段,其中包含一行人及其在测试中的结果:
<tr>
<td>John Doe</td>
<td>18</td>
</tr>
<tr>
<td>Jane Dober</td>
<td>28</td>
</tr>
<my-own-tr-component></my-own-tr-component>
In the end of the table above, I want to add a final <tr>
, which will be my custom component, which will be reused elsewhere. 在上表的最后,我想添加一个最终的
<tr>
,这将是我的自定义组件,并将在其他地方重用。
The problem is that my custom component inserts a dom element in a table which is not a <tr>
which breaks the DOM, styling etc. 问题是我的自定义组件将dom元素插入到不是
<tr>
的表中,该元素会破坏DOM,样式等。
How can I make Angular NOT insert its own host element and just display the <tr>
from my custom component? 如何使Angular不插入自己的宿主元素,而仅显示自定义组件中的
<tr>
?
I don't want to use attribute selectors since it seems like a hack, and is against Angulars style guide document. 我不想使用属性选择器,因为它看起来像是一种hack,并且违反了Angulars风格指南文档。
Give the component the table-row
display property: 为组件提供
table-row
显示属性:
:host { display: table-row; }
That will make it behave for all practical purposes like <tr>
. 这将使它在所有实际用途(例如
<tr>
。 To be precise, it is the display: table-row
property defined in the user agent style sheet that makes <tr>
function as a table row. 确切地说,正是用户代理样式表中定义的
display: table-row
属性使<tr>
用作表行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.