Angularjs filter and custom filter
Angularjs filter and custom filter detailed learning points: 1. angularjs filter 2. use filter3. custom filter 1 in the controller. angularjs filter 1. uppercase, lowercase size conversion {"lower cap string" | uppercase} // result: lower cap string {"TANK is GOOD" | lowercase} // result: tank is good2. json format {foo: "bar", baz: 23} | json} // result: {"foo": "bar", "baz ": 23} 3. date formatting {1304375948024 | date} // result: May 3, 2011 {1304 375948024 | date: "MM/dd/yyyy @ h: mma" }}// result: 05/03/2011 @ AM {1304375948024 | date: "yyyy-MM-dd hh: mm: ss "}}// result: 2011-05-03 06: 39: 084. number formatting {1.234567 | number: 1 }}// result: 1.2 {1234567 | number} // result: 1,234,567 5. currency formatting {250 | currency }}// result: $250.00 {250 | currency: "RMB ¥" }}// result: RMB ¥250.006. filter query {[{"age": 20, "id": 10, "name": "iphone" },{ "age": 12, "id": 11," Name ":" sunm xing "},{" age ": 44," id ": 12," name ":" test abc "}] | filter: 'S '} // find the row containing s // result of the preceding example: [{"age": 12, "id": 11, "name ": "sunm xing" },{ "age": 44, "id": 12, "name": "testabc"}] {[{"age": 20, "id": 10, "name": "iphone" },{ "age": 12, "id": 11, "name": "sunm xing "}, {"age": 44, "id": 12, "name": "test abc"}] | filter: {'name ': 'iphone '}}// find the row whose name is iphone // result of the previous example: [{"age": 20, "id": 10, "name ": "iphone"}] 7. limitTo String to intercept the image {"I love tank" | limitTo: 6} // result: I love {"I love tank" | limitTo: -4 }}// result: tank {[{"age": 20, "id": 10, "name": "iphone" },{ "age ": 12, "id": 11, "name": "sunm xing" },{ "age": 44, "id": 12, "name ": "test abc"}] | limitTo: 1} // result: [{"age": 20, "id": 10, "name ": "iphone"}] 8. orderBy sort objects {[{"age": 20, "id": 10, "name": "iphone" },{ "age": 12, "id ": 11, "name": "sunm xing" },{ "age": 44, "id": 12, "name ":" Test abc "}] | orderBy: 'id': true} // sort the root id in descending order {[{" age ": 20," id ": 10, "name": "iphone" },{ "age": 12, "id": 11, "name": "sunm xing" },{ "age ": 44, "id": 12, "name": "test abc"}] | orderBy: 'id'} // sort by id in ascending order. the controller uses filter $ scope. name = $ filter ('date') ('000000', 'hh'); $ scope. name = $ filter ('uppercase') ('hello'); 3. angularjs custom filter 1. filters. add a module in js to view the copy and print? Angular. module ('tanktest', []). filter ('tankreplace ', function () {return function (input) {return input. replace (/tank/, "====") };}); 2. app. how can I load this module in js to view the copy and print? Var phonecatApp = angular. module ('phonecatapp', comment 'ngroute', 'phonecatcontrollers', 'facebookcontrollers', 'tanktest'{}3.html to call to view copy and print? {"TANK is GOOD" | lowercase | tankreplace} // result: ====== is good note: | lowercase | tankreplace pipeline commands can have multiple