JMaylin
JMaylin

Reputation: 1396

AngularJS: prevent a 404 error in img src attribute

I want to load the thumbnail of video

<img src="http://www.dailymotion.com/thumbnail/video/{{video.id}}">

But until AngularJS is loaded, I get a 404 error

GET http://www.dailymotion.com/thumbnail/video/%7B%7Bvideo.id%7D%7D 404 (Not Found)

It's not a big deal, but I would like to solve it.

Upvotes: 18

Views: 11050

Answers (1)

Eduard Gamonal
Eduard Gamonal

Reputation: 8031

You should be using ng-src or the image url will be resolved literally. a video like http://www.dailymotion.com/thumbnail/video/4 does exist, but not the literal string http://www.dailymotion.com/thumbnail/video/{{video.id}}

I made a jsfiddle demonstrating the img ng-src behaviour. You can see with the network tab in Firebug that you don't get a 404 error.

Upvotes: 36

Related Questions