Angularjs Learning Notes Filter

Source: Internet
Author: User

Filter is a very useful interface for filtering data, such as searching by a field, formatting data, and so on. The following is a brief introduction to its usage.

Angularjs Filter Interface, | is the filter separator, parameters: delimited;

Currency, format number, monetization, the default is converted to USD param (number,symbol), the return value will be 3 digits per comma

<inputtype= "Number"Ng-model= "Amount"/><P>Default USD: {{amount|currency}}</P><P>RMB: {{amount|currency: ' ¥ '}}</P><P>Null: {{amount|currency: '}}</P>

Results:

Date: Formatted time, param (date| Date,number,string,format) Filter: Filter Array,param (string|object|function, second parameter not clear) JSON: Converts an object into a JSON-like string Li Mitto: Limits the length of a string or array, if the argument is positive (positive), starts with beginning, and if a negative number (negative) begins with end lowercase: lowercase uppercase: Uppercase number: The number of decimal points, the default is 3 bits, the return value will be the number of every 3 digits plus a comma-by-order: the array to sort, param (string|function|array,reverse); The basic usage of custom filter is the following example:
varModuleName = Angular.module (' modulename '), []);//filtering on StringsModulename.filter (' FilterName ',function() {    return function(data) {//Do something to change the data value,but dont the data type.        returndata; }})//filtering on the arrayModulename.filter (' Plus15 ',function() {    return function(Orginalarr) {vararr = []; Angular.foeach (function(value, key) {if(Value >= 15) {Arr.push (value); }        })        returnarr; }})

HTML use:

<ng-repeat= "value in Historydata | plus15">    <Li  >{{value.day|filtername}}:{{value.temp}}</li></  ul>

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.