表達(dá)式用于應(yīng)用程序數(shù)據(jù)綁定到HTML。表達(dá)式都寫在雙括號(hào)就像{{表達(dá)式}}。表達(dá)式中的行為跟ng-bind指令方式相同。 AngularJS應(yīng)用表達(dá)式是純javascript表達(dá)式,并輸出它們被使用的數(shù)據(jù)在那里。
使用數(shù)字
<p>Expense on Books : {{cost * quantity}} Rs</p>使用字符串
<p>Hello {{student.firstname + " " + student.lastname}}!</p>使用對(duì)象
<p>Roll No: {{student.rollno}}</p>使用數(shù)組
<p>Marks(Math): {{marks[3]}}</p>例子
下面的例子將展示上述所有表達(dá)式。
testAngularJS.html 文件代碼如下:
<html><title>AngularJS Expressions</title><body><h1>Sample Application</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="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js"></script></body></html>輸出
在Web瀏覽器打開(kāi)textAngularJS.html。看到結(jié)果如下:

新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注