Reading Mastering Web Development with AngularJS, I'm trying to create and use a new filter that uses the $filter module/keyword.
HTML
<div ng-controller="MyCtrl">
<table>
<thead>
<th>Name</th>
<th>Description</th>
</thead>
<tbody>
<tr ng-repeat="item in backlog | trim:4">
<td>{{item}}</td>
</tr>
</tbody>
</table>
</div>
JavaScript
angular.module("myApp", [])
.filter("trim", function($filter) {
var limitToFilter = $filter("limitTo");
return function(input, limit) {
console.log("input:", input, "limit:", limit);
if(input.length > limit) {
return limitToFilter(input, limit-3) + "...";
}
return input;
};
});
function MyCtrl($scope) {
$scope.backlog = ["asdfasdf", "BBBBBBBBB", "CCCCCCC",
"DDDDDDD", "EEEE"];
}
I would've expected the first character (4-3 = 1) of each $scope.backlog item to show up. But it appears to print out the first characters of the first item in $scope.backlog, which doesn't make sense to me.