How can I use variable interpolation in HTML attributes (Knockout.js)?

I use Knockout.js as a data binding framework and a plugin that allows the {{expr}} syntax in my views. So far, so good. But I would also like to use this syntax in HTML attributes. Any ideas how I can do this?

Work

<textarea>{{input}}</textarea>
<input type="text" data-bind="attr:{'value': input}" />
<input type="text" data-bind="value: input" />

Does not work

<input type="text" value="{{input}}" />

A working demo can be found here: http://jsfiddle.net/dC3Ge/1/

thank

+4
source share
1 answer

Michael Best, ko's main committer, has a Knockout.Punches project that meets your exact needs.

http://mbest.imtqy.com/knockout.punches/

+5

Source: https://habr.com/ru/post/1533912/


All Articles