AutoComplete

AutoComplete function of input field.
Import

When To Use#

When there is a need for autocomplete functionality.

Examples#

Basic Usage, set nzDataSource of nz-autocomplete with dataSource property.

      Loading...
    

You could pass nz-auto-option as Content of nz-autocomplete, instead of using nzDataSource`.

      Loading...
    
RMB

Use nzAutocompleteOrigin and nzAutocompleteConnectedTo to specify the origin of the autocomplete overlay. The overlay position and default width are based on the origin element.

      Loading...
    
22.1.0
      Loading...
    

Add status to AutoComplete with nzStatus, which could be error or warning.

      Loading...
    

Use compareWith(SelectControlValueAccessor) when the nzValue and ngModel type is object.

      Loading...
    

Customize Input Component

      Loading...
    

A non-case-sensitive AutoComplete

      Loading...
    
      Loading...
    

Variant is supported out of the box by using nz-input and setting nzVariant to outlined, underlined, filled and borderless

      Loading...
    

API#

<input nz-input [(ngModel)]="value" [nzAutocomplete]="auto" />
<nz-autocomplete [nzDataSource]="['12345', '23456', '34567']" #auto></nz-autocomplete>
<input nz-input [(ngModel)]="value" [nzAutocomplete]="auto" />
<nz-autocomplete #auto>
  <nz-auto-option [nzValue]="'12345'">12345</nz-auto-option>
  <nz-auto-option [nzValue]="'23456'">23456</nz-auto-option>
  <nz-auto-option [nzValue]="'34567'">34567</nz-auto-option>
</nz-autocomplete>

[nzAutocomplete]#

PropertyDescriptionTypeDefaultVersion
[nzAutocomplete]used to bind nzAutocomplete componentsNzAutocompleteComponent-
[nzAutocompleteConnectedTo]element relative to which the autocomplete panel is positionedNzAutocompleteOriginDirectiveautocomplete trigger22.1.0

[nzAutocompleteOrigin]#

Directive applied to an element to make it usable as the origin of an autocomplete panel.

nz-autocomplete#

PropertyDescriptionTypeDefaultVersion
[nzBackfill]backfill selected item the input when using keyboardbooleanfalse
[nzDropdownMatchSelectWidth]Whether dropdown's width is same width than select.booleantrue22.1.0
[nzDataSource]Data source for autocompleteAutocompleteDataSource-
[nzDefaultActiveFirstOption]Whether active first option by defaultbooleantrue
[nzWidth]Custom width, unit pxnumbertrigger element width
[nzOverlayClassName]Class name of the dropdown root elementstring-
[nzOverlayStyle]Style of the dropdown root elementobject-
[compareWith]Same as SelectControlValueAccessor(o1: any, o2: any) => boolean(o1: any, o2: any) => o1===o2

nz-auto-option#

PropertyDescriptionTypeDefault
[nzValue]bind ngModel of the trigger elementany-
[nzLabel]display value of the trigger elementstring-
[nzDisabled]disabled optionbooleanfalse

FAQ#

Q: The overlay layer element does not follow the scroll position when scrolling#

By default, the overlay layer element uses body as the scroll container. If using another scroll container, add the CdkScrollable directive to the custom scroll container element. Note: You need to import the CdkScrollable directive or ScrollingModule module from @angular/cdk/scrolling.