13

I am filling in <img src= tags using AngularJS, so urls in my html are:

<img src='[[profile.image]]'>

When I load the page the image shows but the get errors in the Javascript console too:

GET [[profile.image]] 404 (NOT FOUND) 

So the browser is trying to fetch the image before Angular has interpolated the value right? Then when Angular sets the value the browser fetches again and this time shows the image.

How can I either get Angular to do this earlier, or get the browser to wait? I don't like having the error exposed.

1

1 Answer 1

27

Angular has a special directive just for this case: http://docs.angularjs.org/api/ng.directive:ngSrc

<img ng-src="{{profile.img}}" />
Sign up to request clarification or add additional context in comments.

1 Comment

angularjs is awesome. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.