Created
September 24, 2014 17:17
-
-
Save denarced/d534317e782c83f58e9b to your computer and use it in GitHub Desktop.
Adapt JQueryUI autocomplete to work with angularJs
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
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