0.0.1 • Published 10 years ago

angular-starts-with-filter v0.0.1

Weekly downloads
6
License
-
Repository
github
Last release
10 years ago

#angular-starts-with-filter NPM version Bower version Github version

A simple filter that will return strings that start with a given character.

Installation

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']);

Usage

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]}}

HTML

<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>

Javascript

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'}
		];
		
	}]);

Output

Simple array of strings output:

  • Apple

Object array output:

  • Apple

Build

$ grunt build