表達(dá)式用于將應(yīng)用程序數(shù)據(jù)綁定到HTML。表達(dá)式寫在雙花括號內(nèi),例如{{expression}}中。表達(dá)式的行為類似于ngbind指令。AngularJS表達(dá)式是純JavaScript表達(dá)式,并在使用它們的地方輸出數(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>
以下示例顯示了所有上述表達(dá)式的使用-
<html> <head> <title>AngularJS表達(dá)式</title> </head> <body> <h1>示例應(yīng)用程序</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)絡(luò)瀏覽器中打開文件testAngularJS.htm并查看結(jié)果。