- Angular UI Development with PrimeNG
- Sudheer Jonna Oleg Varaksin
- 224字
- 2021-07-15 17:33:03
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.
- 計(jì)算思維與算法入門
- R語言數(shù)據(jù)分析從入門到精通
- Learn to Create WordPress Themes by Building 5 Projects
- Developing Mobile Web ArcGIS Applications
- 算法訓(xùn)練營:入門篇(全彩版)
- 鋒利的SQL(第2版)
- 大學(xué)計(jì)算機(jī)基礎(chǔ)(第2版)(微課版)
- PostgreSQL Replication(Second Edition)
- 琢石成器:Windows環(huán)境下32位匯編語言程序設(shè)計(jì)
- Python數(shù)據(jù)分析從0到1
- 第一行代碼 C語言(視頻講解版)
- 計(jì)算機(jī)應(yīng)用基礎(chǔ)案例教程
- 征服C指針(第2版)
- 3ds Max 2018從入門到精通
- 你好!Python