AngularJS Basic ng src Simple Example

  • 2021-07-07 06:29:37
  • OfStack

AngularJS ng-src Directive

AngularJS instance

Add picture address:


<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></script>
</head>
<body ng-app="">

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

<p> This instance can use the native  src  Output, but use the  AngularJS  Code inserts values, using the  ng-src  Attributes are better. </p>

</body>
</html>

Definition and usage

The ng-src directives override the < img > The src attribute of the element.

If you use the 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 a picture before execution.

Grammar

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

< img > Element supports this attribute.

Parameter value

描述
string 表达式返回的字符串。

Above on AngularJS ng-src data collation, follow-up to continue to supplement, thank you for your support to this site!


Related articles: