<md-autocomplete>
is a special input component with a drop-down of all possible matches to a
custom query. This component allows you to provide real-time suggestions as the user types
in the input area.
To start, you will need to specify the required parameters and provide a template for your
results. The content inside md-autocomplete
will be treated as a template.
In more complex cases, you may want to include other content such as a message to display when
no matches were found. You can do this by wrapping your template in md-item-template
and
adding a tag for md-not-found
. An example of this is shown below.
You can use ng-messages
to include validation the same way that you would normally validate;
however, if you want to replicate a standard input with a floating label, you will have to
do the following:
md-item-template
ng-messages
code inside of md-autocomplete
md-autocomplete
(ie. required
)name
to md-autocomplete
(to be used on the generated input
)There is an example below of how this should look.
###Basic Example
###Example with "not found" message
In this example, our code utilizes md-item-template
and md-not-found
to specify the
different parts that make up our component.
In this example, our code utilizes md-item-template
and md-not-found
to specify the
different parts that make up our component.
Parameter | Type | Description |
---|---|---|
* md-items
expression
|
expression |
An expression in the format of |
md-selected-item-change
expression
|
expression |
An expression to be run each time a new item is selected |
md-search-text-change
expression
|
expression |
An expression to be run each time the search text updates |
md-search-text
string
|
string |
A model to bind the search query text to |
md-selected-item
object
|
object |
A model to bind the selected item to |
md-item-text
string
|
string |
An expression that will convert your object to a single string. |
placeholder
string
|
string |
Placeholder text that will be forwarded to the input. |
md-no-cache
boolean
|
boolean |
Disables the internal caching that happens in autocomplete |
ng-disabled
boolean
|
boolean |
Determines whether or not to disable the input field |
md-min-length
number
|
number |
Specifies the minimum length of text before autocomplete will make suggestions |
md-delay
number
|
number |
Specifies the amount of time (in milliseconds) to wait before looking for results |
md-autofocus
boolean
|
boolean |
If true, will immediately focus the input element |
md-autoselect
boolean
|
boolean |
If true, the first item will be selected by default |
md-menu-class
string
|
string |
This will be applied to the dropdown menu for styling |
md-floating-label
string
|
string |
This will add a floating label to autocomplete and wrap it in
|
md-input-name
string
|
string |
The name attribute given to the input element to be used with FormController |
md-input-id
string
|
string |
An ID to be added to the input element |
md-input-minlength
number
|
number |
The minimum length for the input's value for validation |
md-input-maxlength
number
|
number |
The maximum length for the input's value for validation |
md-select-on-match
boolean
|
boolean |
When set, autocomplete will automatically select exact the item if the search text is an exact match |