详解AngularJS中的表达式使用
作者:bea
表达式用于应用程序数据绑定到HTML。表达式都写在双括号就像{{表达式}}。表达式中的行为跟ng-bind指令方式相同。 AngularJS应用表达式是纯javascript表达式,并输出它们被使用的数据在那里。 使用数字 <p>Expense on Books : {{cost * quantity}} Rs</p> 使用字符串 <p>Hello {{student.firstname + " " + student.lastn
表达式用于应用程序数据绑定到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。看到结果如下:
有用 | 无用
<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的内部语言环境
- 详解AngularJS中自定义指令的使用
- 详解AngularJS中的依赖注入机制
- 详解AngularJS中的作用域
- 简介AngularJS中使用factory和service的方法
- 简介AngularJS的视图功能应用
- 在AngularJS中使用AJAX的方法
- 使用AngularJS来实现HTML页面嵌套的方法
- AngularJS的表单使用详解
- 举例讲解AngularJS中的模块
- 简介AngularJS的HTML DOM支持情况
- 在Ubuntu系统上安装Ghost博客平台的教程
- JavaScript AOP编程实例
- js+HTML5基于过滤器从摄像头中捕获视频的方法
- 动态加载jQuery的方法
- 详解AngularJS中的表格使用
- js+HTML5实现视频截图的方法
- AngularJS中的过滤器使用详解
- 简述AngularJS的控制器的使用