Autocomplete
Angular Bootstrap 5 Autocomplete component
Autocomplete component predicts the words being typed based on the first few letters given by the user. You can search the list using basic scroll and the keyboard arrows.
Note: Read the API tab to find all available options and advanced customization
Basic example
Display value
The displayValue
option allow to separate original result value from the value
that will be displayed in the result list or input (after selection). Its useful when the data
returned by the filter method is an array of objects. You can specify which
parameter of the object should be displayed.
Asynchronous search
The function passed to the filter
option can return a Promise
that
resolves to an array of results. By default the component expects to receive data as an array
of strings. If you want to return an array of objects instead, you can use
displayValue
option to specify which parameter should be used as a display value
of the specific result.
Threshold
Use threshold
option to specify a minimum number of the characters in the input
field needed to perform a search operation.
Custom item template
It is possible to customize the appearance of the autocomplete option. You can
use the listHeight
option to modify the result list height when you want to
display more content in the component dropdown.
Custom content
A custom content container with a class .autocomplete-custom-content will be displayed at the end of the autocomplete-custom-item-subtitle dropdown. You can use it to display a number of search results.
Reactive forms
Validation
Autocomplete - API
Import
Inputs
Name | Type | Default | Description |
---|---|---|---|
displayValue
|
Function | (value) => value |
Function executed for complex search results, to get value to display in the results list ue |
optionHeight
|
number | 38 |
Changes the single option height value |
listHeight
|
number | 190 |
Height of the results list |
Outputs
Name | Type | Description |
---|---|---|
closed
|
EventEmitter<void> | Event emitted when the dropdown has been closed |
opened
|
EventEmitter<void> | Event emitted when the dropdown has been opened |
selected
|
EventEmitter<MdbAutocompleteSelectedEvent> | Event emitted when the autocomplete's item has been selected |
Methods
Name | Description | Example |
---|---|---|
open |
Manually opens an autocomplete |
autocomplete.open()
|
close |
Manually closes an autocomplete |
autocomplete.close()
|