English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

AngularJS ng-srcset directive

AngularJS Reference Manual

AngularJS Example

Define the resource address of the image:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="https://cdn.staticfile.org/angular.js/1.4.6/angular.min.js"></script>
</head>
<body ng-app="">
<div ng-init="myVar = 'http://www.oldtoolbag.com/wp-content/uploads/2014/06/angular.jpg'">
<h1>Angular</h1>
The <img ng-srcset="{{myVar}}">
</div>
<p>This example can use the native srcset output, but when using AngularJS code to insert values, use the ng-srcset attribute is better.</p>
</body>
</html>
Test to see ‹/›

Definition and Usage

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

If you have used AngularJS code to set the image address, please use ng-srcset Directive Replacement srcset attribute.

ng-srcset The directive ensures that the image is not displayed before the AngularJS code is executed.

Syntax

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

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

Parameter Value

ValueDescription
stringThe string returned by the expression.

AngularJS Reference Manual