表达式用于将应用程序数据绑定到HTML.表达式写在双花括号内,例如{{expression}}.表达式的行为类似于ngbind指令. AngularJS表达式是纯JavaScript表达式,并输出使用它们的数据.
使用数字
Expense on Books : {{cost * quantity}} Rs
使用字符串
Hello {{student.firstname + " " + student.lastname}}!
使用对象
Roll No: {{student.rollno}}
使用数组
Marks(Math): {{marks[3]}}
示例
以下示例显示了使用上述所有表达式 :
testAngularJS.htm
AngularJS Expressions Sample Application
Hello {{student.firstname + " " + student.lastname}}!
Expense on Books : {{cost * quantity}} Rs
Roll No: {{student.rollno}}
Marks(Math): {{marks[3]}}
输出
在网络浏览器中打开文件 testAngularJS.htm 并查看结果.