2

We can use image src with src and ng-src in angular js

 <img src="theme/image.png" alt="Image"/>

AND

<img ng-src="theme/image.png" alt="Image"/> 

I do not feel any difference between them in showing image.is there any difference? I have a project with views are loading from an external site,do i need to change every src to ng-src?does it create any performance issue when i try to load large number of images?

1
  • Just use ng-* scopes when your values are scope statements Commented Jul 1, 2015 at 12:49

2 Answers 2

6

Let me quote

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.

Read more: https://docs.angularjs.org/api/ng/directive/ngSrc

Sign up to request clarification or add additional context in comments.

Comments

2

If the URL of the image is static, you can use src attribute on image.

<img src="theme/image.png" alt="Image"/>

When the URL of image is dynamic and need to set from Controller, use ng-src. any string which can contain {{}} markup

<img ng-src="{{theme}}/image.png" alt="Image"/>
//   ^^^     ^^^^^^^^^

DOCS

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.

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.