Filters for AngularJS filter filter

Source: Internet
Author: User
Tags tojson

First, built-in filter

1, case conversion:

Uppercase, lowercase
{{' Lower cap string ' | uppercase}} {"Tank is good" | lowercase}}  

2.JSON format (Convert object to JSON string), the default output is JSON string:

    {{{name: ' Zhangsan ', Age:15}}}      {{{name: ' Zhangsan ', Age:15}|json}}  

3, Numberformat:

    {{1.2345|number:1}}  1.2    {{1.2345|number:3}}/  /1.235    {1234567|number}}  //1,234,567

4.currecy currency format:

    {{500|currency}}  $500.00    {{250|currency: ' Rmb¥ '}}  //rmb¥250.00

5.Date Format:

    var app = Angular.module (' myApp ', []);      App.controller (' Myctrl ', function ($scope) {          $scope. Dateone = new Date ();          Console.info (New Date (). ToJSON ());          $scope. Datetwo = new Date (). ToJSON ();          /date (1464941268937)/          $scope. Datethree = ' 1464941268937 ';      });  

  

    {{1304375948024 |date}}  May 3,    {{Dateone |date: ' Hh:mm:ss '}}  //09:19:20    {{datetwo |date: ' Yyyy-mm-dd hh:mm:ss '}}  2017-09-19 09:19:20    {{datethree |date: ' YYYY year mm month DD Day '}}  //June 03, 2016

6.Filter Search:

    Find the line containing 4      {{[{"Age": "id": Ten, "Name": "iphone"},      {"Age": "id": one, "name": "Sunm Xing"},      {"Age": 44, "id": "Name": "Test ABC"}]       | filter: ' 4 '}}      //Find the name of the line containing the iphone      {{[{"Age": "id": Ten, "Name": "iphone"},      {"Age": "id": one, "name": "Sunm Xing"},      {"Age": $, "id": +, "name": "Test ABC"}]       | filter:{' name ': ' iphone '}}  

  

    Look for the row containing 4     [{"Age": $, "id": +, "name": "Test ABC"}]     //Find the name of the line containing the iphone     [{"Age": "id": "" Name ":" iphone "}]

7.LimitTo string or object interception:

    {' I want you ' | limitto:3}}  I w    {{' I want you ' | limitto:-3}}  //You    {{[1,3,5]|limitto:1}}  //[1]     {{[1,3,5]|limitto : -1}}  //[5]

8.Sort by order of objects:

    According to the ID descending row          {{[{"Age": "id": Ten, "Name": "iphone"},      {"Age": "id": one, "name": "Sunm Xing"},      {"Age": 44, " ID ":", "name": "Test ABC"}]       | order: ' ID ': true}}           //According to the ID ascending order        {{[{"Age": "id": Ten, "Name": "iphone"},      {"Age": "id": one, "name": "Sunm Xing"},      {"Age": $, "id": +, "name": "Test ABC"}]       | By: ' ID '}}           

  

    Sorted by ID Descending     [{"Age": $, "id": +, "name": "Test abc"},{"Age": "id": one, "name": "Sunm Xing"},{"Age": "id": 10, " Name ":" "iphone"}]    //based on the ID ascending order     [{"Age": +, "id": Ten, "Name": "iphone"},{"Age": "id": one, "name": "Sunm Xing"}, {"Age": $, "id": +, "name": "Test abc"}]

  

Second, custom filter

  

    var app = Angular.module (' myApp ', []);    App.controller (' Myctrl ', function ($scope) {        $scope. msg = "Runoob";    });    App.filter (' Reverse ', function () {//can inject dependent        return function (text) {            return Text.split (""). Reverse (). Join ("") ;        }    });

  

Filters for AngularJS filter filter

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.