I have an anchor tag with an icon inside it like this:
<a>
<i class="icon-flip-2"></i>
hello
</a>
I would like to replace the hello text with an binded element. Something like:
<a data-bind="text: myValue">
<i class="icon-flip-2"></i>
hello
</a>
The problem is that I lost the element < i class="icon-flip-2">
I want to keep it and be able to bind something on the anchor tag.
Thanks.
Any idea?
Knockout provides built-in bindings to enable and disable input elements. The enable binding will enable the input element if the property it's bound to evaluates to true, and will disable the element if it evaluates to false.
Knockout. js defines an important role when we want to detect and respond to changes on one object, we uses the observable. An observable is useful in various scenarios where we are displaying or editing multiple values and require repeated sections of the UI to appear and disappear as items are inserted and deleted.
KO is able to create a two-way binding if you use value to link a form element to an Observable property, so that the changes between them are exchanged among them. If you refer a simple property on ViewModel, KO will set the form element's initial state to property value.
Use a virtual element
<a>
<i class="icon-flip-2"></i>
<!-- ko text: myValue --><!-- /ko -->
</a>
or a <span>
<a>
<i class="icon-flip-2"></i>
<span data-bind="text: myValue, if: myValue().length > 0"></span>
</a>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With