2

I use AngularJS in my website and some images are loaded like this:

<img ng-cloak src="{{ person.username }}"/>

the problem is that I get 404 errors in console that the image is not found because before angular is laoded it tries to load image named {{ person.username }}

How do I solve this?

1
  • 1
    Change src to ng-src. According to angular: Using Angular markup like {{hash}} in a src attribute doesn't work right: The browser will fetch from the URL with the literal text {{hash}} until Angular replaces the expression inside {{hash}}. The ngSrc directive solves this problem. Commented Jul 1, 2015 at 7:44

3 Answers 3

2

Use ng-src

Using Angular markup like {{hash}} in a src attribute doesn't work right: The browser will fetch from the URL with the literal text {{hash}} until Angular replaces the expression inside {{hash}}. The ngSrc directive solves this problem.

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

Comments

1

You can simply use :

ng-src

Example :

<img ng-cloak ng-src="{{ person.username }}"/>

Comments

0

The problem is, that the browser tries to load the resource before the expression is evaluated by angular. That's why there are build in directives as ng-href or ng-src that should be used.

Comments

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.