A simple filter that will return strings that start with a given character.
Download angular-starts-with-filter.min.js or install with bower
$ bower install angular-starts-with-filter --save
Load angular-starts-with-filter.js
, then add the starts-with-filter
module to your application.
angular.module('yourApp', ['starts-with-filter']);
The filter works with both basic string arrays, as well as arrays comprised of objects. To filter a specific object property, simply pass the property name as a parameter.
{{expression | startswith : character [: object property]}}
<body ng-app="filterExample">
<div ng-controller="filterCtrl">
<!-- Simple array of strings filtered by the letter 'A' -->
<ul>
<li ng-repeat="item in items | startswith:'A'">{{item}}</li>
</ul>
<!-- An array of objects with a specific property to filter by 'A' -->
<ul>
<li ng-repeat="object in objects | startswith:'A': 'term'">{{item.term}}</li>
</ul>
</div>
</body>
angular.module('filterExample', ['starts-with-filter'])
.controller('filterCtrl', ['$scope', function($scope){
$scope.items = ['Apple', 'Ball', 'Car', 'Dog'];
$scope.objects = [
{term: 'Apple', definition: 'A red or green fruit'},
{term: 'Ball', definition: 'A round childrens toy'},
{term: 'Car', definition: 'A mode of transportation'},
{term: 'Dog', definition: 'A four-legged domestic pet'}
];
}]);
Simple array of strings output:
- Apple
Object array output:
- Apple
$ grunt build