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

Commit

Permalink
feat(typeahead): expose index to custom templates
Browse files Browse the repository at this point in the history
Closes #699
  • Loading branch information
pkozlowski-opensource committed Jul 26, 2013
1 parent fe47c9b commit 5ffae83
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/typeahead/test/typeahead.spec.js
Expand Up @@ -232,14 +232,14 @@ describe('typeahead tests', function () {

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

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

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>");
var inputEl = findInput(element);

changeInputValueTo(element, 'Al');

expect(findMatches(element).eq(0).find('p').text()).toEqual('Alaska');
expect(findMatches(element).eq(0).find('p').text()).toEqual('0 Alaska');
}));
});

Expand Down
1 change: 1 addition & 0 deletions src/typeahead/typeahead.js
Expand Up @@ -284,6 +284,7 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position'])
return {
restrict:'E',
scope:{
index:'=',
match:'=',
query:'='
},
Expand Down
2 changes: 1 addition & 1 deletion template/typeahead/typeahead-popup.html
@@ -1,5 +1,5 @@
<ul class="typeahead dropdown-menu" ng-style="{display: isOpen()&&'block' || 'none', top: position.top+'px', left: position.left+'px'}">
<li ng-repeat="match in matches" ng-class="{active: isActive($index) }" ng-mouseenter="selectActive($index)" ng-click="selectMatch($index)">
<typeahead-match match="match" query="query" template-url="templateUrl"></typeahead-match>
<typeahead-match index="$index" match="match" query="query" template-url="templateUrl"></typeahead-match>
</li>
</ul>

0 comments on commit 5ffae83

Please sign in to comment.