本文实例讲述了AngularJS自定义过滤器用法。分享给大家供大家参考,具体如下:
过滤器结构
{{带过滤数据 | 过滤器名:参数1:参数2:参数3.....}}
app.filter('过滤器名', function () {
return function (待过滤数据, 参数....) {
......
return 已过滤数据;
}
示例一:是否包含
| Name |
Phone |
| {{friend.name}} |
{{friend.phone}} |
示例二:倒序
姓名:{{ name }}
倒序:{{ name | reverse }}
倒序并大写:{{ name | reverse:true }}
示例三:替换
{{welcome | replaceHello}}
{{welcome | replaceHello:3:5}}
示例四:筛选
自定义过滤器
-
序号
姓名
性别
年龄
分数
-
{{$index+1}}
{{stu.name}}
{{stu.sex}}
{{stu.age}}
{{stu.score}}
示例五:排序
表头排序
-
序号
姓名
性别
年龄
分数
-
{{$index+1}}
{{stu.name}}
{{stu.sex}}
{{stu.age}}
{{stu.score}}
示例六:输入过滤
字符查找
-
序号
姓名
性别
年龄
分数
-
{{$index+1}}
{{stu.name}}
{{stu.sex}}
{{stu.age}}
{{stu.score}}