Home » AngularJS ng-srcset Directive

AngularJS ng-srcset Directive

by Online Tutorials Library

AngularJS ng-srcset Directive

The AngularJS ng-srcset directive is used to solve the problem where original srcset attribute doesn’t work properly. AngularJS ng-srcset overrides the original srcset attribute of an element.

The ng-srcset directive should be used instead of srcset when you have AngularJS code inside the srcset value. It ensures that the image is not displayed wrong before AnglarJS code is executed.

It is supported by <image> and <source> element.

For example:

The wrong way to write this:

The right way to write this:

Syntax:

Parameter explanation:

string: It specifies a string value, or an expression resulting in a string.

Let’s take an example to demonstrate the usage of ng-srcset directive.

See this example:

Test it Now

You may also like