Skip to content
This repository was archived by the owner on May 29, 2019. It is now read-only.

Commit 5ffae83

Browse files
feat(typeahead): expose index to custom templates
Closes #699
1 parent fe47c9b commit 5ffae83

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

src/typeahead/test/typeahead.spec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -232,14 +232,14 @@ describe('typeahead tests', function () {
232232

233233
it('should support custom templates for matched items', inject(function ($templateCache) {
234234

235-
$templateCache.put('custom.html', '<p>{{ match.label }}</p>');
235+
$templateCache.put('custom.html', '<p>{{ index }} {{ match.label }}</p>');
236236

237237
var element = prepareInputEl("<div><input ng-model='result' typeahead-template-url='custom.html' typeahead='state as state.name for state in states | filter:$viewValue'></div>");
238238
var inputEl = findInput(element);
239239

240240
changeInputValueTo(element, 'Al');
241241

242-
expect(findMatches(element).eq(0).find('p').text()).toEqual('Alaska');
242+
expect(findMatches(element).eq(0).find('p').text()).toEqual('0 Alaska');
243243
}));
244244
});
245245

src/typeahead/typeahead.js

+1
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position'])
284284
return {
285285
restrict:'E',
286286
scope:{
287+
index:'=',
287288
match:'=',
288289
query:'='
289290
},
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<ul class="typeahead dropdown-menu" ng-style="{display: isOpen()&&'block' || 'none', top: position.top+'px', left: position.left+'px'}">
22
<li ng-repeat="match in matches" ng-class="{active: isActive($index) }" ng-mouseenter="selectActive($index)" ng-click="selectMatch($index)">
3-
<typeahead-match match="match" query="query" template-url="templateUrl"></typeahead-match>
3+
<typeahead-match index="$index" match="match" query="query" template-url="templateUrl"></typeahead-match>
44
</li>
55
</ul>

0 commit comments

Comments
 (0)