AngularJS: Custom Filters

Source: Internet
Author: User

表达式:          {{ expression | filter1 | filter2 | ... }}          {{ expression | filterName : parameter1 : ...parameterN }}          ng-repeat="a in array | filter "First, a single parameter filter:
Original data: A SCI
Filter data: A SCI [additional content: Single parameter in this filter! ] This lesson source:
123456 < Code class= "HTML Plain" >< h3 > first filter: </ h3 >< BR /> Original data: {{names[0].name}}< BR /> Filtering data: {{names[0].name | filter1}}
123456 app.filter(‘filter1‘, function(){    returnfunction(item){        returnitem + ‘[追加内容:单参数在此过滤!]‘;    }});
Two, the second type with parameter filter:
Original data: A SCI
Filter DATA: A SCI!!!!! The source of this lesson:
123456 <h3>二、第二种带参数过滤器:</h3><br/>原有数据:{{names[0].name}}<br/>过滤数据:{{names[0].name | filter2:5 }}
123456789 app.filter(‘filter2‘, function(){    return function(item,num){        for(var i = 0;i < num;i++){            item = item + ‘!‘;        }        return item;    }});
Three, the third type of array filter:
    • 0, aa===
    • 1, bb===
    • 2, vv===
    • 3, mm===
The source of this lesson:
1234567 < h3 > three, third array filter: </ h3 >< BR /> < ul > &NBSP;&NBSP;&NBSP;&NBSP; < li ng-repeat = "word in [' AA ', ' BB ', ' vv ', ' mm '] | Filter3 " >{{word}}</ li > </ ul >
1234567891011 app.filter(‘filter3‘, function(){    return function(items){        angular.forEach(items,function(item, i){            item = i+‘、‘+ item + ‘===‘;            console.log(item);            items[i] = item;        });        return items;    }});
Four, first letter capital filter:
This was Angular Js Course on each.com The source code of this lesson:
12345 <h3>四、首字母大写过滤器:</h3><br/>{{‘this is angular js course on each.com‘ | filter4}}
12345678910 app.filter(‘filter4‘, function(){    return function(input) {        var words = input.split(‘ ‘);        for (var i = 0; i < words.length; i++) {          words[i] = words[i].charAt(0).toUpperCase() + words[i].slice(1);        }        return words.join(‘ ‘);    }});

AngularJS: Custom Filters

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.