Skip to content

Instantly share code, notes, and snippets.

@denarced
Created September 24, 2014 17:17
Show Gist options
  • Save denarced/d534317e782c83f58e9b to your computer and use it in GitHub Desktop.
Save denarced/d534317e782c83f58e9b to your computer and use it in GitHub Desktop.
Adapt JQueryUI autocomplete to work with angularJs
angular.module('mod').directive('dnAutocomplete', function() {
function link(scope, element, attrs) {
scope.$watch(attrs.dnAutocomplete, function(names) {
element.autocomplete({
source: names,
/**
* The default implementation updates the HTML input's value
* in such a way that the angular doesn't detect it. The
* result is that scope.add.input isn't updated while the
* HTML input itself is. By updating angular's scope object,
* both the HTML input and the model are updated.
*/
select: function(event, ui) {
scope.add.input = ui.item.value;
}
});
}, true);
}
return {
link: link
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment