表達式用于將應用程序數(shù)據(jù)綁定到HTML。表達式寫在雙花括號內(nèi),例如{{expression}}中。表達式的行為類似于ngbind指令。AngularJS表達式是純JavaScript表達式,并在使用它們的地方輸出數(shù)據(jù)。
<p>Expense on Books : {{cost * quantity}} Rs</p><p>Hello {{student.firstname + " " + student.lastname}}!</p><p>Roll No: {{student.rollno}}</p><p>Marks(Math): {{marks[3]}}</p>以下示例顯示了所有上述表達式的使用-
<html>
<head>
<title>AngularJS表達式</title>
</head>
<body>
<h1>示例應用程序</h1>
<div ng-app = "" ng-init = "quantity = 1;cost = 30;
student = {firstname:'Mahesh',lastname:'Parashar',rollno:101};
marks = [80,90,75,73,60]">
<p>Hello {{student.firstname + " " + student.lastname}}!</p>
<p>Expense on Books : {{cost * quantity}} Rs</p>
<p>Roll No: {{student.rollno}}</p>
<p>Marks(Math): {{marks[3]}}</p>
</div>
<script src = "https://cdn.staticfile.org/angular.js/1.3.14/angular.min.js">
</script>
</body>
</html>測試看看?/?輸出結(jié)果
在網(wǎng)絡瀏覽器中打開文件testAngularJS.htm并查看結(jié)果。
