THE WORLD'S LARGEST WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

AngularJS ng-srcset Directive


Example

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

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

Definition and Usage

The ng-srcset directive overrides the original srcset attribute of an element.

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

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


Syntax

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

Supported by the <img> and <source> elements.


Parameter Values

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