Javatpoint Logo
Javatpoint Logo

AngularJS ng-src Directive

The AngularJS ng-src directive is used to solve the problem where original src attribute doesn't work properly. So AngularJS ng-src directive is used and it overrides the original src attribute of an <img> element.

The ng-src directive should be used instead of src when you have AngularJS code inside the src value. It ensures that the image is not displayed wrong before AnglarJS code is executed.

For example:

The wrong way to write this:

The right way to write this:

Syntax:

Parameter explanation:

string: It specifies a string value, or an expression resulting in a string.

Let's take an example to demonstrate the usage of ng-src directive.

See this example:

Test it Now



Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA