AngularJS ng-srcDirective

AngularJS 参考手册AngularJS Reference Manual


AngularJS Example

Add image address:

<div ng-init="myVar = 'http://www.example.com/wp-content/uploads/2014/06/angular.jpg'">
    <h1>Angular</h1>
    <img ng-src="{{myVar}}">
</div>

Try it yourself »

Definition and Usage

ng-srcThe directive overrides the src attribute of the <img> element.

If you use AngularJS code to set the image address, please useng-srcthe directive instead ofsrcthe attribute.

ng-srcThe directive ensures that the image is not displayed before AngularJS code executes.


Syntax

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

The <img> element supports this attribute.


Parameter Value

Value Description
string The string returned by the expression.

AngularJS 参考手册AngularJS Reference Manual

Other Extensions