SHAN KEVIN
SHAN KEVIN

Reputation: 11

When we need to use <!-- ko -->

What situation we should use the<"!--ko--"> and <"!--/ko--">" to cover the code.

Because in normal situation I just use data-bind in tag. But I always see the <"!--ko --"> in many code. But I really do not know what is that means and why we use this.

Upvotes: 1

Views: 198

Answers (2)

Michael Best
Michael Best

Reputation: 16688

Most of the time it's just a personal or code-style preference. In some cases, one or the other is required. For example, sometimes there isn't a valid enclosing element for a set of html:

<tr>
    <td>Row header</td>
    <!-- ko foreach: rows -->
        <td data-bind="text: rowValue"></td>
    <!-- /ko -->
</tr>

Upvotes: 2

Mateen Kajabadi
Mateen Kajabadi

Reputation: 3644

There are some situations that you don't have any container element to use your data-binding tag. For example you have a ul and li but you need to have a fixed default li for your foreach or you need to have a default option in your select binding, in that case the containerless control flow syntax comes handy.
Example :

<ul>
    // Blow "li" is fixed with a different class
    <li class="fixed-title">Title</li>
    <!-- ko foreach: Items -->
        <li data-bind="text: $data"></li>
    <!-- /ko -->
</ul>

Upvotes: 2

Related Questions