# Angular AutoComplete Data Binding

The [Angular AutoComplete](https://www.telerik.com/kendo-angular-ui/components/dropdowns/autocomplete) provides flexible data-binding to display suggestions as the user types. Set the [`data`](https://www.telerik.com/kendo-angular-ui/components/dropdowns/api/autocompletecomponent#data) property to an array of primitive values (strings or numbers) or complex objects.

Choose the binding approach that best fits your data source and application requirements.

You can bind the AutoComplete to:

<Row>
  <Column count={[24,24,12]} style={{marginBottom: "1rem"}}>
    <Component className="tile" href="#binding-to-local-data">
      <ComponentTitle>Local Data</ComponentTitle>
      <ComponentDescription style={{padding: "0 10px 10px 10px"}}>Bind to arrays of primitive values or complex objects that are available on the client-side.</ComponentDescription>
    </Component>
  </Column>
  <Column count={[24,24,12]} style={{marginBottom: "1rem"}}>
    <Component className="tile" href="#binding-to-remote-data">
      <ComponentTitle>Remote Data</ComponentTitle>
      <ComponentDescription style={{padding: "0 10px 10px 10px"}}>Fetch data from a remote endpoint through services, the async pipe, or streaming Observables.</ComponentDescription>
    </Component>
  </Column>
</Row>

## Binding to Local Data

Local data binding refers to providing the data directly in the component. The AutoComplete supports the following local data types:

* [Arrays of primitive data (strings, numbers, or other)](https://www.telerik.com/kendo-angular-ui/components/dropdowns/autocomplete/data-binding#arrays-of-primitive-data)
* [Arrays of complex data (objects)](https://www.telerik.com/kendo-angular-ui/components/dropdowns/autocomplete/data-binding#arrays-of-complex-data)

### Arrays of Primitive Data

To bind the AutoComplete to an array of strings or numbers, assign the array to the [`data`](https://www.telerik.com/kendo-angular-ui/components/dropdowns/api/autocompletecomponent#data) property. No additional configuration is required because the component uses the primitive values directly as both display text and input values.

```html
<kendo-autocomplete [data]="['Albania', 'Andorra', 'Armenia']"></kendo-autocomplete>
```

The following example demonstrates how to bind the AutoComplete to an array of primitive data.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/dropdowns/autocomplete/data_binding/source.txt)

### Arrays of Complex Data

To bind the AutoComplete to an array of objects, set the [`valueField`](https://www.telerik.com/kendo-angular-ui/components/dropdowns/api/autocompletecomponent#valueField) property. The [`valueField`](https://www.telerik.com/kendo-angular-ui/components/dropdowns/api/autocompletecomponent#valueField) property specifies which object field of type `string` the component uses to populate the input value when the user selects an item.

```html
<kendo-autocomplete
    [data]="countries"
    valueField="name">
</kendo-autocomplete>
```

```ts
public countries: Array<{ name: string; code: string }> = [
    { name: "Albania", code: "AL" },
    { name: "Andorra", code: "AD" },
    { name: "Armenia", code: "AM" },
];
```

The following example demonstrates how to bind the AutoComplete to an array of complex data.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/dropdowns/autocomplete/data_binding/complex_data/source.txt)

## Binding to Remote Data

For remote data scenarios, the AutoComplete supports the following approaches:

* [Using a service](https://www.telerik.com/kendo-angular-ui/components/dropdowns/autocomplete/data-binding#services)—Fetch data through an Angular service and assign the results to the [`data`](https://www.telerik.com/kendo-angular-ui/components/dropdowns/api/autocompletecomponent#data) property.
* [Using the async pipe](https://www.telerik.com/kendo-angular-ui/components/dropdowns/autocomplete/data-binding#async-pipe)—Bind an Observable directly to the [`data`](https://www.telerik.com/kendo-angular-ui/components/dropdowns/api/autocompletecomponent#data) property by using the Angular [`async`](https://angular.dev/api/common/AsyncPipe) pipe.
* [Streaming data](https://www.telerik.com/kendo-angular-ui/components/dropdowns/autocomplete/data-binding#streaming-of-data)—Bind to an Observable that emits values over time.

### Services

You can fetch data from a remote endpoint through an Angular service and assign the result to the [`data`](https://www.telerik.com/kendo-angular-ui/components/dropdowns/api/autocompletecomponent#data) property. This approach gives you full control over request parameters and response handling.

The following example demonstrates how to bind the AutoComplete to remote data by using a service.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/dropdowns/autocomplete/remote_binding/source.txt)

### Async Pipe

To bind the AutoComplete directly to an Observable, use the Angular [`async`](https://angular.dev/api/common/AsyncPipe) pipe. The [`async`](https://angular.dev/api/common/AsyncPipe) pipe subscribes to the Observable and updates the [`data`](https://www.telerik.com/kendo-angular-ui/components/dropdowns/api/autocompletecomponent#data) property automatically when new data arrives.

```html
<kendo-autocomplete [data]="countries$ | async"></kendo-autocomplete>
```

```ts
public countries$: Observable<any> = this.service.getCountries();
```

The following example demonstrates how to bind the AutoComplete to an asynchronous source.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/dropdowns/autocomplete/async_sources/source.txt)

### Streaming of Data

The AutoComplete also supports binding to Observables that emit values over time. Use the [`async`](https://angular.dev/api/common/AsyncPipe) pipe to subscribe to the Observable and update the suggestion list as new values arrive.

```html
<kendo-autocomplete [data]="listItems | async"></kendo-autocomplete>
```

```ts
public listItems: Observable<string[]> = interval(1000).pipe(
    map((x) => "New item " + x),
    // Emit suggestions in batches so the list updates five items at a time.
    bufferCount(5)
);
```

The following example starts with an empty Observable, produces one random value each second, and emits values in batches of five.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/dropdowns/autocomplete/data_binding/streaming_data/source.txt)

## Suggested Links

* [Filtering](https://www.telerik.com/kendo-angular-ui/components/dropdowns/autocomplete/filtering)
* [API Reference of the AutoComplete](https://www.telerik.com/kendo-angular-ui/components/dropdowns/api/autocompletecomponent)
