一、过滤器扩展

  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. 用INFORMATION_SCHEMA逻辑MySQL的索引

    分库分表的场景下,变更目前还不知道有哪个表变更索引失败,是不是所有的表都变更成功了,所以可以从INFORMATION_SCHEMA通过罗列索引个数,或者查看索引行,就可以知道是不是所有的都变更成功了: ...

  2. angular1的 伪MVC

    以下的代码是自己对angular1的一些理解.如果非要按照mvc的这种模式开发..可以用以下的这种方式理解. //userFactorys.js 这是服务方法 return 的方法取得json数据里的 ...

  3. Redis---1、介绍

    Redis简介: 是以key-value形式存储,和传统的关系型数据库不一样,不一定遵循传统数据库的一些基本要求. 优点: 对数据高并发读写 对海量数据的高效率存储和访问 对数据的可扩展性和高可用行 ...

  4. 面向对象(基础oop)之进入继承

    大家好,我叫李京阳,,很高兴认识大家,之所以我想开一个自己的博客,就是来把自己所了解的知识点通过自己的话写一下,希望被博客园的朋友们点评和一起讨论一下,也希望从博客园中多认识一些软件开发人员!现在我开 ...

  5. spring mybatis 关于 basepackage 和 mapperLocations 的通配符匹配实例

    SqlSessionFactoryBean mapperLocations 注意下面几点 classpath* mapperLocation 起始路径不能有 * ,如 dm* 就不行 ** list ...

  6. 如何使Wpf浏览器应用程序被完全信任运行

    原文地址链接:http://blogs.microsoft.co.il/maxim/2008/03/05/how-to-run-wpf-xbap-as-full-trust-application/ ...

  7. C#画个控件,指定字符特殊颜色显示

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  8. 【SPOJ】MGLAR10 - Growing Strings

    Gene and Gina have a particular kind of farm. Instead of growing animals and vegetables, as it is us ...

  9. react 共享数据流

    层层传递Props 单向数据流层层传递,繁琐不好管理. Context 什么是context? context是react提供的组件通信api context有什么用? 解决{组件.js}中多层级组件 ...

  10. Function Object in C++

    Function object is very userful to use member function or non-member function as callback mechanism, ...