Typeahead
A text input that suggests values while the user types. The user can pick a suggestion or keep their own text.
Bootstrap’s typeahead docs describe the markup and CSS.
Example
Add bsTypeahead to a text input and give it a search function that returns the suggestions for a term. The input stays a native input, so bind it with [formControl], [(ngModel)] or [formField]. It follows the ARIA combobox pattern: ↓ and ↑ move through the suggestions, Enter picks one and Escape closes the list. Screen readers hear how many suggestions there are.
Value: none
<div bsFormField>
<label bsFormLabel>Country</label>
<input bsFormControl [bsTypeahead]="search" [formControl]="country" />
<small bsFormText>Type to see suggestions, or enter any country.</small>
</div>
<p class="mt-3 mb-0">Value: {{ country.value || 'none' }}</p>Async search and custom items
The search can return a promise or an observable, so it can call a server. Only the answer to the latest term is shown, and debounce (200 ms by default) waits for the user to pause. For objects, formatter turns a suggestion into text, and itemTemplate renders each one. itemSelect emits the picked suggestion.
Picked: none
<div bsFormField>
<label bsFormLabel>Framework</label>
<input
bsFormControl
[bsTypeahead]="search"
[formatter]="name"
[itemTemplate]="item"
(itemSelect)="picked.set($event)" />
</div>
<p class="mt-3 mb-0">Picked: {{ picked()?.name ?? 'none' }}</p>
<ng-template #item let-framework let-text="text">
<span class="menu-item-content">
<span>{{ text }}</span>
<small class="menu-item-description">{{ framework.language }}</small>
</span>
</ng-template>API
BsTypeahead
Selector: input[bsTypeahead] · Exported as: bsTypeahead
Inputs
| Name | Type | Default | Description |
|---|---|---|---|
bsTypeahead | (term: string) => T[] | Promise<T[]> | Observable<T[]> | Finds the suggestions for a term. Required. | |
formatter | (item: T) => string | String | Text shown for a suggestion and put in the input when it is picked. |
itemTemplate | TemplateRef | null | null | Template for each suggestion. Context: $implicit (the suggestion), term and text. |
minLength | number | 1 | Characters to type before searching. |
debounce | number | 200 | Milliseconds to wait after the last keystroke before searching. |
placement | BsPlacement | 'bottom-start' | Where the list opens relative to the input. |
listLabel | string | 'Suggestions' | Accessible label of the suggestion list. |
resultsText | (count: number) => string | '3 suggestions available' | Text announced to screen readers when suggestions arrive. |
Outputs
| Name | Type | Description |
|---|---|---|
itemSelect | T | Emits the suggestion the user picked, after the input is updated. |
Methods
| Name | Type | Description |
|---|---|---|
close() | void | Closes the suggestion list. |
isOpen | Signal<boolean> | Whether the suggestion list is showing. |