I had a read of the documentation http://knockoutjs.com/documentation/attr-binding.html but could not understand why
<img data-bind="attr: {src: imgname}"/>
works but
<img data-bind="src: imgname"/>
does not…
What exactly does this attr binding do and what is so special about src?
Why should the
"src: imgname"work?There are only a couple of built-in bindings in Knockout for controlling text appearance and these are the following:
So as you see
srcis not in the list. All the built-ones are more or less self explenatory but when you want to bind to some other attribute without a built in support e.g.srcyou need to use the genericattrsyntax.As also mentioned in the documentation: