This code throws the error (in Chrome): “Cannot find closing comment tag to match: ko foreach: MyPlans”:
<table>
<!-- ko foreach: MyPlans -->
<tr>
<td>Test</td>
</tr>
<!-- /ko -->
</table>
If I use a list instead, everything works:
<ul>
<!-- ko foreach: MyPlans -->
<li>
Test
</li>
<!-- /ko -->
</ul>
I would like to use the containerless foreach with a table. Is there something I’m doing wrong? Is it a bug?
This is related to the fact that browsers insert
tbodytags automatically, which creates a mismatch in the comments. The rendered output will look like:Steve did put some work into trying to correct mismatched tags in KO, but the easiest thing for you to do is either add the
tbodyyourself or add thetbodyand put your binding on it.It is legal for a table to have multiple
tbodytags, if necessary.