THE INDIA LARGEST WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

AngularJS ng-src Directive


Example

Add an image, where the src is evaluated by AngularJS:

<div ng-init="myVar = 'pic_angular.jpg'">
    <h1>Angular</h1>
    <img ng-src="{{myVar}}">
</div>
Try it yourself »

Definition and Usage

The ng-src directive overrides the original src attribute of an <img> element.

The ng-src directive should be used instead of src if you have AngularJS code inside the src value.

The ng-src directive makes sure the image is not displayed wrong before AngularJS has evaluated the code.


Syntax

<img ng-src="string"></img>

Supported by the <img> element.


Parameter Values

Value Description
string A string value, or an expression resulting in a string.