美文网首页
[基础] angular 过滤器介绍

[基础] angular 过滤器介绍

作者: Top_Chenxi | 来源:发表于2017-06-14 10:34 被阅读21次

[基础] angular 过滤器介绍

用法

HTML

{{ name | uppercase }}

javascript

app.controller('DemoController', ['$scope', '$filter',
    function($scope, $filter) {
        $scope.name = $filter('lowercase')('Ari');
    }
]);

过滤器介绍:
currency - 数值格式化为货币格式
date - 将日期格式化成需要的格式

{{ today | date:'medium' }} <!-- Aug 09, 2013 12:09:02 PM -->
{{ today | date:'short' }} <!-- 8/9/1312:09PM -->
{{ today | date:'fullDate' }} <!-- Thursday, August 09, 2013 -->
{{ today | date:'longDate' }} <!-- August 09, 2013 -->
{{ today | date:'mediumDate' }}<!-- Aug 09, 2013 -->
{{ today | date:'shortDate' }} <!-- 8/9/13 -->
{{ today | date:'mediumTime' }}<!-- 12:09:02 PM -->
{{ today | date:'shortTime' }} <!-- 12:09 PM -->

<!-- 
    官方解析
    `'yyyy'`: 4 digit representation of year (e.g. AD 1 => 0001, AD 2010 => 2010)
    `'yy'`: 2 digit representation of year, padded (00-99). (e.g. AD 2001 => 01, AD 2010 => 10)
    `'y'`: 1 digit representation of year, e.g. (AD 1 => 1, AD 199 => 199)
    `'MMMM'`: Month in year (January-December)
    `'MMM'`: Month in year (Jan-Dec)
    `'MM'`: Month in year, padded (01-12)
    `'M'`: Month in year (1-12)
    `'LLLL'`: Stand-alone month in year (January-December)
    `'dd'`: Day in month, padded (01-31)
    `'d'`: Day in month (1-31)
    `'EEEE'`: Day in Week,(Sunday-Saturday)
    `'EEE'`: Day in Week, (Sun-Sat)
    `'HH'`: Hour in day, padded (00-23)
    `'H'`: Hour in day (0-23)
    `'hh'`: Hour in AM/PM, padded (01-12)
    `'h'`: Hour in AM/PM, (1-12)
    `'mm'`: Minute in hour, padded (00-59)
    `'m'`: Minute in hour (0-59)
    `'ss'`: Second in minute, padded (00-59)
    `'s'`: Second in minute (0-59)
    `'sss'`: Millisecond in second, padded (000-999)
    `'a'`: AM/PM marker
    `'Z'`: 4 digit (+sign) representation of the timezone offset (-1200-+1200)
    `'ww'`: Week of year, padded (00-53). Week 01 is the week with the first Thursday of the year
    `'w'`: Week of year (0-53). Week 1 is the week with the first Thursday of the year
    `'G'`, `'GG'`, `'GGG'`: The abbreviated form of the era string (e.g. 'AD')
    `'GGGG'`: The long form of the era string (e.g. 'Anno Domini')
-->

json -- 将一个JSON或JavaScript对象转换成字符串

{{ {'name': 'Ari', 'City': 'SanFrancisco'} | json }} 
<!-- {"name": "Ari", "City": "San Francisco"} -->

limitTo -- 根据传入的参数生成一个新的数组或字符串

{{ San Francisco is very cloudy | limitTo:3 }}
<!-- San -->
{{ San Francisco is very cloudy | limitTo:-6 }}
<!-- cloudy -->
{{ ['a','b','c','d','e','f'] | limitTo:1 }}
<!-- ["a"] -->

lowercase -- 字符串转为小写

{{ "San Francisco is very cloudy" | lowercase }}
<!-- san francisco is very cloudy -->

uppercase -- 字符串转换为大写

{{ "San Francisco is very cloudy" | uppercase }}
<!-- SAN FRANCISCO IS VERY CLOUDY -->

number -- 将数字格式化成文本

{{ 123456789 | number }}
<!-- 1,234,567,890 -->

orderBy -- 用表达式对指定的数组进行排序

{{ 
    [{'name': 'Ari', 'status': 'awake'},
    {'name': 'Q', 'status': 'sleeping'},
    {'name': 'Nate', 'status': 'awake'}] | orderBy:'name' 
}} 
<!-- [{"name":"Ari","status":"awake"}, {"name":"Nate","status":"awake"}, {"name":"Q","status":"sleeping"} ] -->

相关文章

  • [基础] angular 过滤器介绍

    [基础] angular 过滤器介绍 用法 HTML javascript 过滤器介绍:currency - 数值...

  • AngularJs 自定义过滤器

    除了之前介绍的几种设定好的过滤器之外,angular还允许自定义过滤器。 用例: ...

  • 关注博客

    介绍angular2基础模块

  • 关于angular与vue在过滤器方面的不同

    目前看来,angular与vue在过滤器方面差异较大,总的来说angular的过滤器较简单方便,vue的过滤器更像...

  • [翻译]入门angular的 Service Workers

    原文 前期准备 如下的基础知识: Angular service workers介绍. 从5angular.0.0...

  • Angular Route导航

    Angular Route导航 路由基础知识 路由相关对象介绍 新建路由项目 使用angular-cli新建项目。...

  • 管道Angular 4 - Pipes

    在本章中,我们将讨论Angular 4中的管道。管道早先在Angular1中称为过滤器,在Angular 2和4中...

  • angular过滤器

    过滤器改变显示方式: 一,angular中的内置过滤器 1.过滤¥,$符号 |currency (保留小数点...

  • angular2管道pipe

    谁用angular2自定义管道写过过滤器,搜索类似于angular1中firter的功能?急急

  • Vue与Angular、React的区别

    Angular的区别 相同点:都支持指令:内置指令和自定义指令。都支持过滤器:内置过滤器和自定义过滤器。都支持双向...

网友评论

      本文标题:[基础] angular 过滤器介绍

      本文链接:https://www.haomeiwen.com/subject/xvdsqxtx.html