AngularJS ng-src Directive

Definition and Usage

ng-src Directive will override <img> The original src attribute.

If you include AngularJS code in the src value, you should use ng-src Directive replaces src.

ng-src Directives ensure that the image will not be displayed incorrectly before the AngularJS code is evaluated.

Example

Add an image where src is calculated by AngularJS:

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

Try it yourself

Syntax

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

Affected <img> Element support.

Parameter

Parameter Description
string String value, or expression result is a string.