AngularJS基础知识笔记之过滤器
过滤器是用来更改修改数据,并且可以在表达式或使用管道符指令将其归入。以下是常用的过滤器的列表。
S.No. 名称 描述
1 大写 转换文本为大写文本。
2 小写 转换文本为小写文本。
3 货币 货币格式格式文本。
4 过滤器 过滤数组中它根据所提供的标准的一个子集。
5 排序 排序提供标准的基础数组。 大写过滤器
添加大写的过滤器使用管道符的表达式。在这里,添加了大写过滤器,全部用大写字母打印学生姓名。
Enter first name:<input type="text" ng-model="student.firstName">
Enter last name: <input type="text" ng-model="student.lastName">
Name in Upper Case: {{student.fullName() | uppercase}}
小写过滤器
添加小写的过滤器,使用管道符的表达式。在这里添加小写过滤器,以小写字母打印学生姓名。
Enter first name:<input type="text" ng-model="student.firstName">
Enter last name: <input type="text" ng-model="student.lastName">
Name in Upper Case: {{student.fullName() | lowercase}}
货币滤波器
加币过滤器使用管道符返回数的表达式。在这里,我们添加了过滤器,货币使用货币格式的打印费用。
Enter fees: <input type="text" ng-model="student.fees">
fees: {{student.fees | currency}}
过滤器的过滤器
要仅显示所需的主题,我们使用subjectName作为过滤器。
Enter subject: <input type="text" ng-model="subjectName">
Subject:
<ul>
<li ng-repeat="subject in student.subjects | filter: subjectName">
{{ subject.name + ', marks:' + subject.marks }}
</li>
</ul>
排序过滤器
要通过标记排序主题,我们使用orderBy标记。
Subject:
<ul>
<li ng-repeat="subject in student.subjects | orderBy:'marks'">
{{ subject.name + ', marks:' + subject.marks }}
</li>
</ul>
例子
下面的例子将展示上述所有的过滤器。
testAngularJS.html
<html>
<head>
<title>Angular JS Filters</title>
</head>
<body>
<h2>AngularJS Sample Application</h2>
<div ng-app="" ng-controller="studentController">
<table border="0">
<tr><td>Enter first name:</td><td><input type="text" ng-model="student.firstName"></td></tr>
<tr><td>Enter last name: </td><td><input type="text" ng-model="student.lastName"></td></tr>
<tr><td>Enter fees: </td><td><input type="text" ng-model="student.fees"></td></tr>
<tr><td>Enter subject: </td><td><input type="text" ng-model="subjectName"></td></tr>
</table>
<br/>
<table border="0">
<tr><td>Name in Upper Case: </td><td>{{student.fullName() | uppercase}}</td></tr>
<tr><td>Name in Lower Case: </td><td>{{student.fullName() | lowercase}}</td></tr>
<tr><td>fees: </td><td>{{student.fees | currency}}</td></tr>
<tr><td>Subject:</td><td>
<ul>
<li ng-repeat="subject in student.subjects | filter: subjectName |orderBy:'marks'">
{{ subject.name + ', marks:' + subject.marks }}
</li>
</ul>
</td></tr>
</table>
</div>
<script>
function studentController($scope) {
$scope.student = {
firstName: "Mahesh",
lastName: "Parashar",
fees:500,
subjects:[
{name:'Physics',marks:70},
{name:'Chemistry',marks:80},
{name:'Math',marks:65}
],
fullName: function() {
var studentObject;
studentObject = $scope.student;
return studentObject.firstName + " " + studentObject.lastName;
}
};
}
</script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js"></script>
</body>
</html>
以上所述就是本文的全部内容了,希望大家能够喜欢。
- 详解AngularJS中的filter过滤器用法
- AngularJS的内置过滤器详解
- 详解AngularJS中自定义过滤器
- 详解AngularJS Filter(过滤器)用法
- AngularJS 过滤器(自带和自建)详解
- 详解AngularJS中$filter过滤器使用(自定义过滤器)
- Angularjs之filter过滤器(推荐)
- AngularJS实现用户登录状态判断的方法(Model添加拦截过滤器,路由增加限制)
- 详解Angularjs在控制器(controller.js)中使用过滤器($filter)格式化日期/时间实例
- AngularJS 过滤器的简单实例
- Angularjs 依赖压缩及自定义过滤器写法
- AngularJS常见过滤器用法实例总结
相关文章
AngularJS实现与Java Web服务器交互操作示例【附demo源码下载】
这篇文章主要介绍了AngularJS实现与Java Web服务器交互操作的方法,结合实例形式较为详细的分析了AngularJS前台ajax提交与javascript后台处理的完整流程与实现技巧,并附带demo源码供读者下载参考,需要的朋友可以参考下2016-11-11
Angular 4依赖注入学习教程之FactoryProvider配置依赖对象(五)
这篇文章主要给大家介绍了关于Angular 4依赖注入之FactoryProvider配置依赖对象的相关资料,文中介绍的非常详细,对大家具有一定的参考学习价值,需要的朋友们下面来一起看看吧。2017-06-06
Angular ng-repeat遍历渲染完页面后执行其他操作详细介绍
这篇文章主要介绍了Angular ng-repeat遍历渲染完页面后执行其他操作详细介绍的相关资料,需要的朋友可以参考下2016-12-12
AngularJs的UI组件ui-Bootstrap之Tooltip和Popover
这篇文章主要介绍了AngularJs的UI组件ui-Bootstrap之Tooltip和Popover,tooltip和popover是轻量的、可扩展的、用于提示的指令。具有一定的参考价值,感兴趣的小伙伴们可以参考一下2018-07-07


最新评论