手机
当前位置:查字典教程网 >编程开发 >Javascript教程 >AngularJS表达式讲解及示例代码
AngularJS表达式讲解及示例代码
摘要:表达式用于应用程序数据绑定到HTML。表达式都写在双括号就像{{表达式}}。表达式中的行为跟ng-bind指令方式相同。AngularJS应...

表达式用于应用程序数据绑定到HTML。表达式都写在双括号就像{{表达式}}。表达式中的行为跟ng-bind指令方式相同。 AngularJS应用表达式是纯javascript表达式,并输出它们被使用的数据在那里。

使用数字

<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>

例子

下面的例子将展示上述所有表达式。

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浏览器打开textAngularJS.html。看到结果如下:

AngularJS表达式讲解及示例代码1

以上就是对AngularJS 表达式的资料整理,后续继续补充相关资料,谢谢大家对本站的支持!

【AngularJS表达式讲解及示例代码】相关文章:

实现DIV圆角的JavaScript代码

在页面中输出当前客户端时间javascript实例代码

JS函数实现鼠标指向图片后显示大图代码

JQuery自动触发事件的方法

AngularJS的内置过滤器详解

Angularjs全局变量被作用域监听的正确姿势

AngularJS学习笔记之ng-options指令

浅析javascript函数表达式

AngularJS 2.0新特性有哪些

JavaScript正则表达式中的ignoreCase属性使用详解

精品推荐
分类导航