[基础] angular 过滤器介绍

[基础] angular 过滤器介绍

用法

HTML

{{ name | uppercase }}

javascript

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

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

{{ today | date:'medium' }} 
{{ today | date:'short' }} 
{{ today | date:'fullDate' }} 
{{ today | date:'longDate' }} 
{{ today | date:'mediumDate' }}
{{ today | date:'shortDate' }} 
{{ today | date:'mediumTime' }}
{{ today | date:'shortTime' }} 


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

{{ {'name': 'Ari', 'City': 'SanFrancisco'} | json }} 

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

{{ San Francisco is very cloudy | limitTo:3 }}

{{ San Francisco is very cloudy | limitTo:-6 }}

{{ ['a','b','c','d','e','f'] | limitTo:1 }}

lowercase -- 字符串转为小写

{{ "San Francisco is very cloudy" | lowercase }}

uppercase -- 字符串转换为大写

{{ "San Francisco is very cloudy" | uppercase }}

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

{{ 123456789 | number }}

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

{{ 
    [{'name': 'Ari', 'status': 'awake'},
    {'name': 'Q', 'status': 'sleeping'},
    {'name': 'Nate', 'status': 'awake'}] | orderBy:'name' 
}} 

你可能感兴趣的:([基础] angular 过滤器介绍)