Simple to use autocomplete directive in a module for AngularJS! Supports arrow keys to traverse suggestions as well as mouse input. You can load the suggestions from a remote REST API, it also supports promises.
Checkout the demo to see what it does.
To use it you need of course AngularJS, so make sure it is loaded first. I always like to use Google's CDN for that:
Also you should load the stylesheet of the autocomplete:
Then in your HTML you should load it before the script of your main app. Like this:
In your main script file you should add it as dependency:
If you now want an autocomplete you can just use the tag
<autocomplete> tag in your HTML. With the
data parameter you can pass in an array that will be used for autocompletion. You need to pass there something which is available in the $scope of your controller.
You can also pass a function that receives changes with the
on-type attribute. This is useful if you need to load external resources from a REST API, for example, you cna then upload the array you passed into
data and it will automatically use the changed array.
data : Pass an array to the autocomplete directive. Should be accessible in the $scope of your controller.
on-type : (optional) Pass a function that will receives changes, when somebody types something. It passes the full string for any character typed or deleted. You can use that for example to update the array that you passed in data.
click-activation : (optional) When
true, the suggestion box opens on click (unfortunately onfoucs is not implemented properly in most browsers right now). By default it is only activated, when you start typing something.
ng-model: What you typed in will be in this variable and accessible in the $scope of the controller.
attr-placeholder: (optional) Sets desired text as placeholder into the input element of autocomplete directive. By default it's "start typing..."
attr-class: (optional) Change the class of the
div containing the
input and suggestions elements, allowing you to change their style according to your needs.
attr-id: (optional) Change the id of the containing
div element, see
attr-input-class: (optional) Set the class of the
input element, allowing you to style the input field directly.
attr-input-id: (optional) Change the id of the
input element, see
<autocomplete ng-model="yourchoice" data="movies" on-type="updateMovies"></autocomplete>