1<! DOCTYPE html>234<meta charset= "UTF-8" >5<title>angular Basics-Custom Filters </title>67<body>8<div ng-app= "MYAPP" >9<div ng-controller= "Myctrl" >Ten One<table border= "1" width= ">" A<th> -<td> name </td> -<td> Age </td> the<td> Height </td> -</th> -<TR ng-repeat= "Item in Items" > -<td>{{$index +1}}</td> +<td>{{item.name}}</td> -<td>{{item.age}}</td> +<td>{{item.stature}}</td> A</tr> at<tr> -<td> Total </td> -<td></td> -<TD ng-bind= "items | Sumage:items: ' Age ' ></td> -<td></td> -</tr> in</table> -</div> to +</div> -<script src= "Http://cdn.static.runoob.com/libs/angular.js/1.4.6/angular.min.js" ></script> the<script type= "Application/javascript" > * varMyapp=angular.module (' myApp ', [' Myapp.filter ']); $ varAppfilter=angular.module (' Myapp.filter ',[]);Panax Notoginseng //Custom Filters -Myapp.filter (' Sumage ',function(){ the //The second argument is summed according to the first argument + return function(input,n1,n2) { AConsole.log ("Input value:" +input); theConsole.log ("First parameter:" +Angular.tojson (N1)); +Console.log ("second parameter:" +n2); - varSum=0; $Angular.foreach (Input,function(item) { $Sum + =Item.age; - }); - returnsum; the } - })Wuyi the</script> -<script> WuMyapp.controller (' Myctrl ', [' $scope ',function($scope) { -$scope. Items = [ About { $Name: ' Lu Xun ', -Age:27, -stature:165 - }, A { +Name: ' Hu Shi ', theAge:25, -stature:170 $ }, the { theName: ' Chekhov ', theAge:27, thestature:175 - }, in { theName: ' Balzac ', theAge:29, Aboutstature:165 the }]; the }]); the</script> +</body> -
angularjs-Custom Filter Ng-repeat sum