1她君,uppercase,lowercase大小轉(zhuǎn)換
{{ "lower cap string" | uppercase }} //結(jié)果:LOWER CAP STRING
{{ "TANK is GOOD" | lowercase }} //結(jié)果:tank is good
|這里的豎線是一種管道功能,如果對linux比較熟悉的話拌禾,這塊的|根linux的管道功能太援,基本是一樣的
2,json格式化
{{ {foo: "bar", baz: 23} | json }} //結(jié)果:{ "foo": "bar", "baz": 23 }
注意:bza沒格式前是沒有雙引號的劫窒,格式化后就轉(zhuǎn)換成了json數(shù)據(jù)了本今。
3,date格式化
{{ 1304375948024 | date }} //結(jié)果:May 3, 2011
{{ 1304375948024 | date:"MM/dd/yyyy @ h:mma" }} //結(jié)果:05/03/2011 @ 6:39AM
{{ 1304375948024 | date:"yyyy-MM-dd hh:mm:ss" }} //結(jié)果:2011-05-03 06:39:08
4主巍,number格式化
{{ 1.234567 | number:1 }} //結(jié)果:1.2
{{ 1234567 | number }} //結(jié)果:1,234,567
5冠息,currency貨幣格式化
{{ 250 | currency }} //結(jié)果:$250.00
{{ 250 | currency:"RMB ¥ " }} //結(jié)果:RMB ¥ 250.00
6,filter查找
{{ [{"age": 20,"id": 10,"name": "iphone"},
{"age": 12,"id": 11,"name": "sunm xing"},
{"age": 44,"id": 12,"name": "test abc"}
] | filter:'s'}} //查找含有有s的行
//上例結(jié)果:[{"age":12,"id":11,"name":"sunm xing"},{"age":44,"id":12,"name":"test abc"}]
{{ [{"age": 20,"id": 10,"name": "iphone"},
{"age": 12,"id": 11,"name": "sunm xing"},
{"age": 44,"id": 12,"name": "test abc"}
] | filter:{'name':'iphone'} }} //查找name為iphone的行
//上例結(jié)果:[{"age":20,"id":10,"name":"iphone"}]
7孕索,limitTo字符串铐达,對像的截取
{{ "i love tank" | limitTo:6 }} //結(jié)果:i love
{{ "i love tank" | limitTo:-4 }} //結(jié)果:tank
{{ [{"age": 20,"id": 10,"name": "iphone"},
{"age": 12,"id": 11,"name": "sunm xing"},
{"age": 44,"id": 12,"name": "test abc"}
] | limitTo:1 }} //結(jié)果:[{"age":20,"id":10,"name":"iphone"}]
8,orderBy對像排序
{{ [{"age": 20,"id": 10,"name": "iphone"},
{"age": 12,"id": 11,"name": "sunm xing"},
{"age": 44,"id": 12,"name": "test abc"}
] | orderBy:'id':true }} //根id降序排
{{ [{"age": 20,"id": 10,"name": "iphone"},
{"age": 12,"id": 11,"name": "sunm xing"},
{"age": 44,"id": 12,"name": "test abc"}
] | orderBy:'id' }} //根據(jù)id升序排
二檬果,自定filter功能
我找了一個基本angularjs的mvc框架瓮孙,phonecat唐断,自定義filter也是在這基礎(chǔ)寫的,這個框架挺好用的杭抠。
1脸甘,filters.js添加一個module
angular.module('tanktest', []).filter('tankreplace', function() {
return function(input) {
return input.replace(/tank/, "=====")
};
});
2,app.js中加載這個module
var phonecatApp = angular.module('phonecatApp', [
'ngRoute',
'phonecatControllers',
'facebookControllers',
'tanktest'
]);
3偏灿,html中調(diào)用
{{ "TANK is GOOD" | lowercase |tankreplace}} //結(jié)果:===== is good