官术网_书友最值得收藏!

Autosuggestion with AutoComplete

AutoComplete is an input component that provides real-time suggestions while the user types into the input field. This enables users to quickly find and select from a list of looked-up values as they type, which leverages the searching and filtering abilities.

A basic usage of the AutoComplete component includes the suggestions attribute to provide the list of all resulted items and completeMethod to filter items based on the typed query. For example, the following AutoComplete component displays the list of countries based on the user query:

<p-autoComplete [(ngModel)]="country" name="basic"
[suggestions]="filteredCountries"
(completeMethod)="filterCountries($event)"
field="name" [size]="30"
placeholder="Type your favourite Country" [minLength]="1">
</p-autoComplete>

In the preceding example, minLength="1" is used as minimum characters for the input to query results. This will render the output as shown in the following snapshot:

As the user types in the input field, the complete method will filter the items on demand. The method has to be defined in the component class, as shown here:

filterCountries(event: any) {
let query = event.query;
this.countryService.getCountries().
subscribe((countries: Country[]) => {
this.filteredCountries = this.filterCountry(query, countries);
});
}

The preceding method allows filtering of the list of countries based on the user query. In this case, it will filter all the countries that start with the query character.

To improve the user experience, AutoComplete provides a drop-down option through the dropdown property. On clicking the drop-down icon, it will populate all possible items in a downwards popup immediately.

主站蜘蛛池模板: 六枝特区| 株洲市| 习水县| 罗定市| 济阳县| 依兰县| 湾仔区| 星子县| 河源市| 嘉义县| 白城市| 柳江县| 紫云| 星子县| 新蔡县| 志丹县| 青阳县| 新兴县| 龙井市| 连州市| 河西区| 昌图县| 怀远县| 桦川县| 托克托县| 上饶县| 永定县| 灌南县| 青田县| 泰兴市| 双辽市| 保德县| 濉溪县| 三台县| 肇庆市| 溆浦县| 奉新县| 唐海县| 资中县| 缙云县| 丰台区|