Created
October 25, 2013 08:03
-
-
Save lotas/7151079 to your computer and use it in GitHub Desktop.
autocomplete.js angular bootstrap-ui
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
autocomplete.directive('suggest', ['$compile', 'AutocompleteService', function ($compile, AutocompleteService) { | |
var cnt = 0; | |
return { | |
require: '', | |
restrict: 'A', | |
replace: true, | |
transclude: true, | |
template: '<input ng-transclude type="text" autocomplete="off" typeahead="item for item in items" />', | |
compile: function (elm, attrs) { | |
++cnt; | |
var type = attrs.suggest, | |
autocompletItems = attrs.items || '', // for non-ajax cases | |
itemsName = 'items' + cnt, | |
funcName = 'completeIt' + cnt; | |
// Selector for the typeahead plugin | |
var selector = 'item for item in ' + funcName + '($viewValue)'; | |
if (type == 'array') { | |
selector = 'item for item in ' + itemsName + '|filter:$viewValue'; | |
} | |
// attach selector | |
$(elm).attr('typeahead', selector); | |
return function ($scope, elm, attrs, ngModel) { | |
$scope[itemsName] = autocompletItems ? autocompletItems.split(',') : []; | |
$scope[funcName] = AutocompleteService.getLookupFunction(type); | |
}; | |
} | |
}; | |
}]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment