表达式:
{{ 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