2
votes

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.

1

1 Answers

3
votes

From this post stems a genious hack:

<img ng-src="modelImage" src="//:0">

...much easier to remember from the top of your head than an image URL ;)

ngSrc: any string which can contain {{}} markup.