Skip to content
This repository has been archived by the owner on Nov 22, 2021. It is now read-only.

Commit

Permalink
feat(autocomplete): Make $index available to custom templates
Browse files Browse the repository at this point in the history
Make the suggestion index available to custom templates via the local
variable $index.
  • Loading branch information
mbenford committed Mar 20, 2015
1 parent 7976122 commit 8611877
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/auto-complete-match.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ tagsInput.directive('tiAutocompleteMatch', function($sce, tiUtil) {
return {
restrict: 'E',
require: '^autoComplete',
template: '<ng-include src="template"></ng-include>',
template: '<ng-include src="$$template"></ng-include>',
scope: { data: '=' },
link: function(scope, element, attrs, autoCompleteCtrl) {
var autoComplete = autoCompleteCtrl.registerAutocompleteMatch(),
options = autoComplete.getOptions();

scope.template = options.template;
scope.$$template = options.template;
scope.$index = scope.$parent.$index;

scope.$highlight = function(text) {
if (options.highlightMatchedText) {
Expand Down
13 changes: 13 additions & 0 deletions test/auto-complete.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1282,6 +1282,19 @@ describe('autoComplete directive', function() {
expect(getSuggestionScope(2).data).toEqual({ id: 3, text: 'Item3', image: 'item3.jpg' });
});

it('makes suggestions\' indexes available to the template', function() {
// Arrange
compile();

// Act
loadSuggestions(3);

// Assert
expect(getSuggestionScope(0).$index).toBe(0);
expect(getSuggestionScope(1).$index).toBe(1);
expect(getSuggestionScope(2).$index).toBe(2);
});

it('makes helper functions available to the template', function() {
// Arrange
compile();
Expand Down

0 comments on commit 8611877

Please sign in to comment.