1、filter (过滤)
{{[{name:’coolcao’,age:23},{name:’lily’,age:20},{name:’tom’,age:22}] | filter:’coolcao’}}
结果:[{“name”:”coolcao”,”age”:23}]
如果要精确过滤,例如只要name为coolcao的可以使用如下:
{{[{name:’coolcao’,age:23},{name:’lily’,age:22},{name:’tom’,age:22}] | filter:{‘name’:’coolcao’} }}
注意:filter 对象使用的大括号和angularjs取值所用的大括号之间要留至少一个空格(就是最后三个大括号倒数第三个和倒数1,2两个大括号之前留至少一个空格,不
然angularjs会解析错误)
{{ [{“age”: 20,”id”: 10,”name”: “iphone”},
{“age”: 12,”id”: 11,”name”: “sunm xing”},
{“age”: 44,”id”: 12,”name”: “test abc”}
] | filter:’s’}} //查找含有有s的行
//上例结果:[{“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的行
//上例结果:[{“age”:20,”id”:10,”name”:”iphone”}]
日期
{{1423130269432 | date:’yyyy-MM-dd HH:mm:ss’}}
时间
{{ 3.1415926 | number:1 }}
{{ 3.1415926 | number:2 }}
{{ -3.1415926 | number:2 }}
{{ 3 | number:2 }}
{{ 0.002 | number:2 }}
{{ 0.009 | number:2 }}
{{ 1234567 | number }} //结果:1,234,567
{{1000 | number}}
{{1000 | number:2}}
4、orderBy 排列
{{[{name:’coolcao’,age:23},{name:’lily’,age:20},{name:’tom’,age:22}] | orderBy:’age’}}
[{“name”:”lily”,”age”:20},{“name”:”tom”,”age”:22},{“name”:”coolcao”,”age”:23}]
默认是升序排列,如果要倒序:
{{[{name:’coolcao’,age:23},{name:’lily’,age:20},{name:’tom’,age:22}] | orderBy:’age’:true}}
或者:
{{ [{“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’ }} //根据id升序排
5、json格式化
{{[{name:’coolcao’,age:23},{name:’lily’,age:22},{name:’tom’,age:22}] | json}}
结果:[ { “name”: “coolcao”, “age”: 23 }, { “name”: “lily”, “age”: 22 }, { “name”: “tom”, “age”: 22 } ]
大小写转换: uppercase,lowercase
{{‘abc’ | uppercase}}
7、currency : 货币的格式化
{{1000 | currency }} $1,000.00
{{1000 | currency:”RMB ¥” }} RMB ¥1,000.00
8、limitTo字符串,对像的截取
{{ “i love tank” | limitTo:6 }} //结果:i love
{{ “i love tank” | limitTo:-4 }} //结果:tank
{{ [{“age”: 20,”id”: 10,”name”: “iphone”},
{“age”: 12,”id”: 11,”name”: “sunm xing”},
{“age”: 44,”id”: 12,”name”: “test abc”}
] | limitTo:1 }} //结果:[{“age”:20,”id”:10,”name”:”iphone”}]