Angular UI Development with PrimeNG
上QQ阅读APP看书,第一时间看更新

Working with objects

Until now, AutoComplete has shown its power on primitive types, but it can work with object types as well. The value passed to the model would be an object instance, but the field property defines the label to be displayed as a suggestion. That is, in this case, the field property is used to display any property of the object as a label. The following example shows the power of the object usage:

<p-autoComplete id="instance" [(ngModel)]="countryInstance" name="instance"
[suggestions]="filteredCountryInstances"
(completeMethod)="filterCountryInstances($event)" field="name">
</p-autoComplete>

In the preceding example, the Country object is used as a model object instance and the suggestions displayed are from the country using the name field property.