AngularJS过滤器
1.过滤器可以使用一个管道字符(|)添加到表达式和指令中。
常见的AngularJS 过滤器
(1) lowercase和uppercase过滤器(大小写)
<div ng-app="myApp" ng-controller="myCtrl">
<p>名字: {{userName|uppercase}}</p><!-- 转化为大写 -->
<p>姓氏: {{lastname|lowercase}}</p><!-- 转化为小写 -->
</div>
<script type="text/javascript">
var app = angular.module('myApp', []);
app.controller('myCtrl',function($scope){
$scope.userName ="hello yyy";
$scope.lastname = "REEfsnes";
});
</script>
结果如下:
(2)Currency过滤器(美元符号)
<div ng-app="myApp" ng-controller="myCtrl">
<p>单价<input type="number" ng-model="price" /></p>
<p>数量<input type="number" ng-model="quantity"/> </p>
<h2 >总价为:{{(price*quantity) | currency}}</h2><!-- 表达式 -->
</div>
<script type="text/javascript">
var app = angular.module('myApp', []);
app.controller('myCtrl',function($scope){
$scope.price = 12;
$scope.quantity = 2;
});
</script>
结果如下:
(3)orderBy过滤器(排序数组)
<div ng-app="myApp" ng-controller="myCtrl">
<!-- 通过国家排序 -->
<p>通过国家排序</p>
<ul>
<li ng-repeat="x in names | orderBy:'country'">
{{ x.name + ', ' + x.country }}
</li>
</ul>
<!-- 通过名字排序 -->
<p>通过名字排序</p>
<ul>
<li ng-repeat="x in names | orderBy:'name'">
{{ x.name + ', ' + x.country }}
</li>
</ul>
</div>
<script type="text/javascript">
var app = angular.module('myApp', []);
angular.module('myApp', []).controller('myCtrl', function($scope) {
$scope.names = [{
name: 'Jemy',
country: 'Norway'
}, {
name: 'Peter',
country: 'Sweden'
}, {
name: 'Kaisa',
country: 'Denmark'
}];
});
</script>
结果如下:
(4)filter过滤器(过滤输入)
<div ng-app="myApp" ng-controller="myCtrl">
<p>输入过滤 <input type="text" ng-model="test"/ placeholder="请输入过滤的字符"></p>
<!-- 过滤输入后通过名字排序 -->
<ul>
<li ng-repeat="x in names| filter:test |orderBy:'name'">
{{ (x.name) + ', ' + x.country }}
</li>
</ul>
</div>
<script type="text/javascript">
var app = angular.module('myApp', []);
angular.module('myApp', []).controller('myCtrl', function($scope) {
$scope.names = [{
name: 'Jemy',
country: 'Norway'
}, {
name: 'Peter',
country: 'Sweden'
}, {
name: 'Kaisa',
country: 'Denmark'
}];
});
输入p后结果如下:
AngularJS过滤器的更多相关文章
- AngularJS过滤器filter-时间日期格式-渲染日期格式-$filter
今天遇到了这些问题索性就 写篇文章吧 话不多说直接上栗子 不管任何是HTML格式还是JS格式必须要在 controller 里面写 // new Date() 获取当前时间 yyyy-MM-ddd ...
- AngularJS 过滤器
过滤器可以使用一个管道字符(|)添加到表达式和指令中 AngularJS 过滤器可用于转换数据: currency 格式化数字为货币格式. filter 从数组项中选择一个子集. lowercase ...
- AngularJS学习之旅—AngularJS 过滤器(七)
1.AngularJS 过滤器 过滤器可以使用一个管道字符(|)添加到表达式和指令中. AngularJS 过滤器可用于转换数据: 过滤器 描述 currency 格式化数字为货币格式. filter ...
- AngularJS 1.x系列:AngularJS过滤器(4)
1. AngularJS过滤器(Filter)使用方法 AngularJS中过滤器(Filter)主要功能是格式化数据. AngularJS过滤器使用方法有3种: ◊ 在表达式{{}}中使用 ◊ 在指 ...
- AngularJS过滤器filter入门
在开发中,经常会遇到这样的场景 如用户的性别分为“男”和“女”,在数据库中保存的值为1和0,用户在查看自己的性别时后端返回的值自然是1或0,前端要转换为“男”或“女”再显示出来: 如我要换个羽毛球拍, ...
- AngularJS控制器和AngularJS过滤器的学习(3)
前面简单的学习了AngularJS的表达式和指令,就可以说大概对AngularJS有了一定的了解吧,嘿嘿,下面就来总结学习一下AngularJS的控制器和过滤器哦. 说起来AngularJS控制器,其 ...
- angularJS 过滤器 表单验证
过滤器1.filter的作用就是接收一个输入,通过某个规则进行处理,然后返回处理后的结果,主要用于数据的格式化.2.内置过滤器(1)Currency(货币)将一个数值格式化为货币格式,默认为$(2)D ...
- angularjs过滤器(一)------禁止转载------
如果用代码实现:将new Date()转换为 M/D/YY 00:00 格式. 启用过滤器有两种方式:①在HTML中用"|"启用过滤器.格式为{{$scope.property | ...
- 关于angularjs过滤器的小尝试
最近的项目中用到了angularjs,相比传统的jquery直接操作Dom, 开发web项目,angularjs在操作表格数据时的数据绑定,操作让我不禁直呼过瘾,好方便啊, 从后台接口传一个json过 ...
随机推荐
- Linux Vsftpd 连接超时解决方法(被动模式)
http://blog.csdn.net/qq_15766181/article/details/46554643 使用 FileZilla FTP Client 连接 Vsftpd FTP,在没有配 ...
- (。・・)ノ~个人java学习随笔记录
基本认识 1.编程思维 根据这几天的java学习,编写程序最重要的就是要有一个清晰的思路.语法上的错误可以跟随着不断的联系与学习来弥补,清晰的思维却只有自己来前期模仿,后面慢慢摸索形成一套属于自己的思 ...
- freebsd 系统时间
http://blog.csdn.net/wowoto/article/details/5557810 https://www.douban.com/note/150233427/ date #查看当 ...
- Oracle知识分类之异常
Oracle异常分类 ...
- ORM系列之二:EF(4) 约定、注释、Fluent API
目录 1.前言 2.约定 2.1 主键约定 2.2 关系约定 2.3 复杂类型约定 3.数据注释 3.1 主键 3.2 必需 3.3 MaxLength和MinLength 3.4 NotMapped ...
- SPI总线
一.概述. SPI, Serial Perripheral Interface, 串行外围设备接口, 是 Motorola 公司推出的一种同步串行接口技术. SPI 总线在物理上是通过接在外围设备微控 ...
- Spring原理解析-利用反射和注解模拟IoC的自动装配
- pip的相关操作
>Python中的pip是什么?能够做些什么? pip是Python中的一个进行包管理的东西,能够下载包.安装包.卸载包......一些列操作 >怎么查看pip的相关信息 在控制台输入: ...
- Yaf(Yet Another Framework)用户手册 yii框架手册
地址:http://www.laruence.com/manual/ yaf框架手册:http://pan.baidu.com/s/1bnHFPHd yii框架手册:http://pan.baidu. ...
- Design and Analysis of Algorithms_Divide-and-Conquer
I collect and make up this pseudocode from the book: <<Introduction to the Design and Analysis ...