Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Anyone has idea, how to produce valid HTML5 when images are displayed with AngularJs ng-scr directive?

What I have discovered?

  • "src"- attribute is required on img-tags
  • It can't be empty
  • Console reports 404 error if I set src attribute data with angular binding, cause it tries to load image before Angular has initialized

Why I want valid HTML?

Reason is simple. Strange HTML errors (missing end tags, open tags etc..) causes strange behavior in our project where we have LOTS of views. Ensuring periodically that source is valid, makes code less unstable.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

more or less a funny solution (if you will not find a way to configure your html validator): just add an image as data url:

<img ng-src="modelImage" src="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==">
share|improve this answer
    
Nailed. Cheers! –  AngularAddict Jan 13 at 18:06
    
Apparently the smallest data uri you can use is src="data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs%3D" reference stackoverflow.com/a/14115340/150342 –  Colin Oct 6 at 13:40

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.