一、过滤器扩展

  1、过滤器的组合使用

<!DOCTYPE HTML>
<html ng-app="myApp">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
<script src="angular.min.js"></script>
<script>
var m1 = angular.module('myApp',[]);
m1.controller('Aaa',['$scope',function($scope){
$scope.name = 'hello';
}]);
</script>
</head>
<body>
<div ng-controller="Aaa">
<p>{{ name | limitTo : 2 | uppercase }}</p>
</div>
</body>
</html>

  2、通过服务的方式在js中使用过滤器

<!DOCTYPE HTML>
<html ng-app="myApp">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
<script src="angular.min.js"></script>
<script>
var m1 = angular.module('myApp',[]);
m1.controller('Aaa',['$scope','$filter',function($scope,$filter){
//$scope.name = $filter('uppercase')('hello'); //对hello进行转大写的操作 //$scope.name = $filter('number')('1326554654');
$scope.name = $filter('number')('1326554654.545485',4); //4表示设置保留的小数位
}]);
</script>
</head>
<body>
<div ng-controller="Aaa">
<p>{{ name }}</p>
</div>
</body>
</html>

二、自定义过滤器

<!DOCTYPE HTML>
<html ng-app="myApp">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
<script src="angular.min.js"></script>
<script>
var m1 = angular.module('myApp',[]); //自定义过滤器
m1.filter('firstUpper',function(){
return function(str,num){
//console.log(num); //num没有什么用,但是可以找到这个num
return str.charAt(0).toUpperCase() + str.substring(1);
}
}); m1.controller('Aaa',['$scope','$filter',function($scope,$filter){
$scope.name = $filter('firstUpper')('hello');
}]);
</script>
</head>
<body>
<div ng-controller="Aaa">
<p>{{ name }}</p>
<p>{{ name | firstUpper }}</p>
</div>
</body>
</html>

angularJs的过滤器扩展及自定义过滤器的更多相关文章

  1. AngularJs练习Demo8 自定义过滤器

    @{ Layout = null; } <!DOCTYPE html> <html> <head> <meta name="viewport&quo ...

  2. angularjs学习第三天笔记(过滤器第二篇---filter过滤器及其自定义过滤器)

    您好,我是一名后端开发工程师,由于工作需要,现在系统的从0开始学习前端js框架之angular,每天把学习的一些心得分享出来,如果有什么说的不对的地方,请多多指正,多多包涵我这个前端菜鸟,欢迎大家的点 ...

  3. VueJs 自定义过滤器使用总结

    过滤器是一个通过输入数据,能够及时对数据进行处理并返回一个数据结果的简单函数.Vue有很多很便利的过滤器,可以参考官方文档, http://cn.vuejs.org/api/#过滤器 ,过滤器通常会使 ...

  4. django之创建第6-1个项目-自定义过滤器

    1.在站点blog目录下创建templatetags文件夹 2.templatetags目录下需要作为一个包来处理和调用其中的内容,需要有一个__init__.py文件 3.在templatetags ...

  5. vue.js学习 自定义过滤器使用(1)

    在这个教程中,我们将会通过几个例子,了解和学习VueJs的过滤器.我们参考了一些比较完善的过滤器,比如orderBy 和 filterBy.而且我们可以链式调用过滤器,一个接一个过滤.因此,我们可以定 ...

  6. vue2.0 自定义过滤器(filter)实例

    一.过滤器简介 (1)过滤器创建 过滤器的本质 是一个有参数 有返回值的方法 new Vue({ filters:{ myCurrency:function(myInput){ return 处理后的 ...

  7. python测试开发django-70.自定义过滤器filter

    前言 django的模板有很多内置的过滤器,可以满足一些常见的需求,如果有些需求内置过滤器无法满足,那么我们需要自己写一些过滤器了. 自定义过滤器 先在app下新建一个 templatetags 目录 ...

  8. DRF框架(九)——drf偏移分页组件、drf游标分页组件(了解)、自定义过滤器、过滤器插件django-filter

    drf偏移分页组件 paginations.py from rest_framework.pagination import LimitOffsetPagination class MyLimitOf ...

  9. drf偏移分页组件-游标分页-自定义过滤器-过滤器插件django-filter

    drf偏移分页组件 LimitOffsetPagination 源码分析:获取参数 pahenations.py from rest_framework.pagination import Limit ...

随机推荐

  1. JAVA练手--文件操作

    1. File类 主要作用:用于文件和文件夹的创建.查找.删除等操作 public static void main(String[] args) throws IOException { File ...

  2. Android Studio 连接 逍遥模拟器

    1.启动 逍遥模拟器: 2.打开 Android Studio 项目: 3.命令行 adb connect 127.0.0.1:21503 C:\Users\Administrator>adb ...

  3. 再说优化MySQL索引

    这几天开发尤其重视数据库索引的优化,是一件好事情,开发特意提过来几个要删除的索引,oh!我的佛陀呀!历史上出现过因为评估不到位,删索引引发故障的案例.那么有什么办法可以评估索引是否合理呢? perco ...

  4. ashx+jsonp+document.referrer

    -- 一年前学的JSONP 跨域,一年后的今天相关知识点基本忘光.花了一天时间重新学习,再次感谢各位前辈的帖子,特此记录如下. --html <!DOCTYPE html PUBLIC &quo ...

  5. javascript window.opener的用法分析

    window.opener 返回的是创建当前窗口的那个窗口的引用 window.opener 的用法 window.opener 返回的是创建当前窗口的那个窗口的引用,比如点击了a.htm上的一个链接 ...

  6. 后台数据校验-BeanCheck

    package com.ldf.domain; import java.text.ParseException; public class UserCheck { //从表单获取的数据 private ...

  7. Groovy中String转换Gstring用于动态插值

    知识点是Groovy中的模板引擎 GStringTemplateEngine 第一个例子: def binding = [ firstname : "Grace", lastnam ...

  8. SqlServer示例数据库Northwind(一)——实体关系

    在学习Spss统计分析.EA画实体关系图.PowerDesigner画数据库模型图等时,苦于找不到一个好的实例.由于实际工作中项目使用的表结构属于公司的商业保密内容,且在和大家交流时,其结构大家也不熟 ...

  9. Code Signal_练习题_alternatingSums

    Several people are standing in a row and need to be divided into two teams. The first person goes in ...

  10. .NET AOP微型框架发布 --CleanAOP

    CleanAOP--简介 作者:立地(欧文) 邮箱:jarvin_g@126.com 导语: AOP为Aspect Oriented Programming的缩写. 意为:面向切面编程.将日志记录,性 ...