AngularJS ng-srcsetDirective

AngularJS 参考手册AngularJS Reference Manual


AngularJS Example

Define the resource address of the image:

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

Try it yourself »

Definition and Usage

ng-srcsetThe directive overrides the srcset attribute of the <img> element.

If you use AngularJS code to set the image address, please use theng-srcsetdirective instead of thesrcsetattribute.

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


Syntax

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

The <img> and <source> elements support this attribute.


Parameter Value

Value Description
string A string returned by an expression.

AngularJS 参考手册AngularJS Reference Manual

Other Extensions