Deep understanding of ANGULARJS filter _angularjs

Source: Internet
Author: User

• Use in HTML files and in JS files

$scope. Form_time = $filter (' Date ') ($scope. Time, ' Yyyy-mm-dd HH:mm:ss ');

<p>{{time | date: ' YYYY-MM-DD HH:mm:ss '}}</p>

• Internal filters and custom filters

. Filter (' My_data_format ', [function () {return
  function (data,str,sss) {
    console.log (' Data: ', data, ' str: ', STR, ' SSS: ', arguments[2]);
  }
];
VAR1 is the first parameter data, 123 is the second parameter str, this is the third parameter
<p>{{var1 | my_data_format:123: ' This '}}</p>


// Processing of incoming data
. Filter (' My_data_format ', [function () {return
  function (data,str) {
    var arr=[];
    Angular.foreach (data, function (one_list) {
      if (one_list.status = str) {
        arr.push (one_list);
      }
    });
    Return arr
  }
]);
Filters can be used in bound values or in ng-if= "(Lists | My_data_format: ' 2 '). Length>0", and Ng-show, and so on; similar expressions. As a judgment statement
<p ng-repeat = "list in lists" > name: {{list.name}}, number {{lists | my_data_format: ' 2 ') .length}}</p>

This in-depth understanding of the ANGULARJS filter is a small series to share all the content, hope to give you a reference, but also hope that we support the cloud-dwelling community.

Related Article

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.