AngularJS中的表达式用于将应用数据绑定到HTML。表达式由Angular解析,结果会被返回到写表达式的地方。AngularJS中的表达式是用双花括号写的:{{expression}}。它们的行为类似于ng-bind指令:ng-bind= " expression "
语法如下:
{{ expression }}
例子:这个例子显示了我们在ng-init指令中输入的名称。
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/
angular.min.js"></script>
<head>
<title>AngularJS Introduction</title>
</head>
<body style = "text-align:center">
<h2 style = "color:green">AngularJS Expressions</h2>
<div ng-app = "" ng-init = "name='lsbin'">
<p> {{ name }} is a portal for geeks.</p>
</div>
</body>
</html>
输出如下:
范例2:此示例显示了我们在ng-init指令中提供的对象的内容。
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/
angular.min.js"></script>
<head>
<title>AngularJS Introduction</title>
</head>
<body>
<h2 style = "color:green">AngularJS Expressions</h2>
<div ng-app = "" ng-init="sort={one:'quick sort', two:'merge sort', three:'bubble
sort'}">
<p> Sorting Algorithms:
<ul>
<li>{{ sort.one }}</li>
<li>{{ sort.two }}</li>
<li>{{ sort.three }}</li>
</ul>
</div>
</body>
</html>
输出如下: