Reputation: 17906
I love knockout.js and I use is very often.
But when I use the "attr-binding" for an img’s src
or alt
attribute, like
data-bind="attr: { src: photo.src, alt: 'description'}"
The W3C-validator says that’s invalid HTML:
Bad value for attribute
src
on elementimg
: Must be non-empty.
And they are right, because the attributes are empty until the model was bound and executed.
Is there any other workaround than providing a link to a wrong image? Or in other words, is it a real problem somebody has been facing before?
Upvotes: 0
Views: 1430
Reputation: 1138
You can try
<img src="#" alt="" data-bind="attr: { src: photo.src, alt: 'description'}" />
Upvotes: 1
Reputation: 14995
You can always use this -
data-bind="attr: { src: photo.src || 'default.jpg' }"
Fiddle example - http://jsfiddle.net/jAYPL/
Upvotes: 0