0

I'm trying to create a Bootstrap table using two Angular components.

My code is organised as following :

componentA.html
<table class="table table-bordered">
<thead>
<tr>
  <th scope="col">#</th>
  <th scope="col">First</th>
  <th scope="col">Last</th>
  <th scope="col">Handle</th>
</tr>
</thead>
 <tbody>
  <componentB></componentB>
 </tbody>
</table>



componentB.html
<tr>
 <th scope="row">1</th>
 <td>Mark</td>
 <td>Otto</td>
 <td>mdo</td>
</tr>

The result should be like this : expected

but it's actually like this : reality

However, it works fine when I put the HTML content of componentB directly in componentA html.

Thank you for your help

2 Answers 2

1

You are missing the scope on tr tag : <th scope="row">1</th>

Then table element in HTML just allows thead, tbody, tfoot and tr as children.

Change your componentB selector from 'componentB' to '[componentB]'

<table class="table table-bordered">
<thead>
<tr>
  <th scope="col">#</th>
  <th scope="col">First</th>
  <th scope="col">Last</th>
  <th scope="col">Handle</th>
</tr>
</thead>
 <tbody componentB>
 </tbody>
</table>
Sign up to request clarification or add additional context in comments.

4 Comments

You are right, I did a poor copy past and forgot that line, but my code was tested with <th scope="row">1</th> and it didn't worked
trying to fix it, the problem should be from the <componentb> not allowed as a tag into a table.
Thank you for your answer, but it's inadvised by Angular best practices to do so. (sources : angular.io/guide/styleguide#style-05-03)
Such case is covered by the exception paragraph : as you can't include non html table children tags, you can only "augment built-in elements."
0
<table class="table table-bordered">
<thead>
<tr>
    <th scope="col">#</th>
    <th scope="col">First</th>
    <th scope="col">Last</th>
    <th scope="col">Handle</th>
</tr>
</thead>
<tbody>
<tr>
    <th scope="row">1</th>
    <td>Mark</td>
    <td>Otto</td>
    <td>@mdo</td>
</tr>
</tbody>

1 Comment

Yeah this is working, but I need to use two differents components in order to create dynamics tables

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.