A directive for providing suggestions while typing into the field
Autocomplete allows for custom html templating in the dropdown and some properties are exposed on the local scope on each template instance, including:
Variable | Type | Details |
---|---|---|
$index |
Number | iterator offset of the repeated element (0..length-1) |
$first |
Boolean | true if the repeated element is first in the iterator. |
$middle |
Boolean | true if the repeated element is between the first and last in the iterator. |
$last |
Boolean | true if the repeated element is last in the iterator. |
$even |
Boolean | true if the iterator position $index is even (otherwise false). |
$odd |
Boolean | true if the iterator position $index is odd (otherwise false). |
item |
Object | item object with value and label if label-key is set |
To use custom templating
<mac-autocomplete mac-autocomplete-url="someUrl" ng-model="model">
<span> {{item.label}} </span>
</mac-autocomplete>
Template default to {{item.label}}
if not defined
Parameters:
Name | Type | Description |
---|---|---|
ng-model |
String | Assignable angular expression to data-bind to (required) |
mac-placeholder |
String | Placeholder text |
mac-autocomplete-source |
Expression | Data to use. Source support multiple types:
|
mac-autocomplete-disabled |
Boolean | Boolean value if autocomplete should be disabled |
mac-autocomplete-on-select |
function | Function called when user select on an item
|
mac-autocomplete-on-success |
function | function called on success ajax request
|
mac-autocomplete-on-error |
function | Function called on ajax request error
|
mac-autocomplete-label |
String | The label to display to the users (default "name") |
mac-autocomplete-query |
String | The query parameter on GET command (default "q") |
mac-autocomplete-delay |
Integer | Delay on fetching autocomplete data after keyup (default 800) |
mac-menu-class |
Expr | Classes for mac-menu used by mac-autocomplete. For more info, check ngClass |
Examples
Basic setup
<mac-autocomplete
mac-autocomplete-source = "autocompleteUrl"
mac-autocomplete-query = "q"
mac-autocomplete-on-success = "onSuccess(data)"
mac-placeholder = "'Autocomplete'"
ng-model = "autocompleteQuery"
></mac-autocomplete>
Example with autocomplete using source
<mac-autocomplete
mac-autocomplete-source = "['hello', 'world']"
mac-placeholder = "'Type something...'"
ng-model = "autocompleteSourceQuery"
></mac-autocomplete>