SoFunction
Updated on 2025-04-07

AngularJS basic ng-src directive simple example

AngularJS ng-src directive

AngularJS instance

Add image address:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="/libs//1.4.6/"></script>
</head>
<body ng-app="">

<div ng-init="myVar = '/wp-content/uploads/2014/06/'">
<h1>Angular</h1>
<img ng-src="{{myVar}}">
</div>

<p>This instance can use native src Output,But use AngularJS Code insert value,use ng-src Better attributes。</p>

</body>
</html>

Definition and usage

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

If you use AngularJS code to set the image address, use the ng-src directive instead of the src attribute.

The ng-src directive ensures that the AngularJS code does not display images before execution.

grammar

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

The <img> element supports this property.

Parameter value

value describe
string The string returned by the expression.

The above is to organize the AngularJS ng-src information and continue to add it in the future. Thank you for your support for this site!