All Components

Data Binding

The ComboBox enables you to bind to a list of possible values.

The list can contain primitive (strings and numbers) or complex (objects) items.

Binding to Local Data

When binding it to local data, the ComboBox provides options for binding it to:

Arrays of Primitive Data

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

@Component({
  selector: 'my-app',
  template: `
    <div class="example-wrapper">
      <kendo-combobox [data]="listItems" [placeholder]="'T-shirt size'"></kendo-combobox>
    </div>
  `
})
class AppComponent {
    public listItems: Array<string> = ["X-Small", "Small", "Medium", "Large", "X-Large", "2X-Large"];
}

Arrays of Complex Data

When the component is bound to complex data (objects), define the textField and valueField properties. The ComboBox will extract the value and text values from the selected data item and in this way will set the selected value and text.

The following example demonstrates how to bind the ComboBox to an array of objects.

@Component({
  selector: 'my-app',
  template: `
    <kendo-combobox
        [data]="listItems"
        [textField]="'text'"
        [valueField]="'value'"
        [placeholder]="'T-shirt size'"
    >
    </kendo-combobox>
  `
})
class AppComponent {
    public listItems: Array<{ text: string, value: number }> = [
        { text: "Small", value: 1 },
        { text: "Medium", value: 2 },
        { text: "Large", value: 3 }
    ];
}

Binding to Remote Data

When binding it to remote data, the ComboBox provides options for:

Services

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

import { Component, OnInit, Inject } from '@angular/core';

import { DataService } from './data.service';
import { Product } from '../common/product.model'

@Component({
  selector: 'my-app',
  template: `
    <kendo-combobox [data]="listItems"
      [textField]="'ProductName'"
      [valueField]="'ProductID'"
      [placeholder]="'Select Product...'" >
    </kendo-combobox>
  `,
  providers:[DataService]
})

export class AppComponent {

    public listItems: Array<Product> = [];

    constructor (private dataService: DataService) { }

    ngOnInit() {
      this.dataService.fetchData().subscribe(
        (data) => this.listItems = data
      )
    }
}
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { HttpClientModule, HttpClientJsonpModule } from '@angular/common/http';
import { FormsModule } from '@angular/forms';
import { DropDownsModule } from '@progress/kendo-angular-dropdowns';

import { AppComponent }   from './app.component';

@NgModule({
  imports: [
    BrowserModule,
    BrowserAnimationsModule,
    FormsModule,
    HttpClientModule,
    HttpClientJsonpModule,
    DropDownsModule
  ],
  declarations: [
    AppComponent
  ],
  bootstrap: [
    AppComponent
  ]
})
export class AppModule { }
import { AppModule } from './ng.module';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';

const platform = platformBrowserDynamic();
platform.bootstrapModule(AppModule);
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Product } from './product.model';
import { Observable } from 'rxjs/Rx';

@Injectable()

export class DataService {
  constructor(private http: HttpClient) { }

  fetchData(action: string = "", data?: Product): Observable<Product[]>{
    return this.http.jsonp<Product[]>(
      `https://demos.telerik.com/kendo-ui/service/Products/${action}?${this.serializeModels(data)}`,
      'callback'
    );
  }

  private serializeModels(data?: Product): string {
    return data ? `&models=${JSON.stringify([data])}` : '';
  }
}
export class Product {
    constructor(
        public ProductID?: number,
        public ProductName?: string,
        public UnitPrice?: number,
        public UnitsInStock?: number,
        public Discontinued?: boolean
    ) { }
}

Async Pipe

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

import { Component } from '@angular/core';
import { Observable } from 'rxjs/Rx';
import { CategoriesService } from './categories.service';

@Component({
    providers: [CategoriesService],
    selector: 'my-app',
    template: `
        <div class="col-lg-4 col-sm-6 form-group">
          <div class="input-group">
        <kendo-combobox
        name="category" [data]="view | async"
          [(ngModel)]="category"
          [valueField]="'CategoryID'"
          [textField]="'CategoryName'"
          [filterable]="true"
          (filterChange)="handleFilter($event)">
        </kendo-combobox>
          </div>
        </div>

  `
})
export class AppComponent {
    private toggleText: string = "Hide";
    private show: boolean = true;
    public category: any;
    private view: Observable<any>;
    public category: any = {};


    constructor(private service: CategoriesService) {
        this.view = service;
    }

    public handleFilter(value) {
        this.service.query(value);
    }
}
import { Injectable } from '@angular/core';
import { HttpClient, HttpClientModule } from '@angular/common/http';

import { BehaviorSubject } from 'rxjs/Rx';

@Injectable()
export class CategoriesService extends BehaviorSubject<any> {
    constructor(private http: HttpClient) {
        super(null);
    }

    public query(): void {
        this.fetch(this.tableName)
            .subscribe(x => super.next(x));
    }

    private BASE_URL: string = 'https://odatasampleservices.azurewebsites.net/V4/Northwind/Northwind.svc/';
    private tableName: string = "Categories";

    private fetch(tableName: string): any {
        const queryStr = `$skip=0&$count=true`;
        return this.http
            .get(`${this.BASE_URL}${tableName}?${queryStr}`)
            .map(response => response['value']);
    }
}
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { HttpClientModule, HttpClientJsonpModule } from '@angular/common/http';
import { FormsModule } from '@angular/forms';
import { DropDownsModule } from '@progress/kendo-angular-dropdowns';

import { AppComponent }   from './app.component';

@NgModule({
  imports: [
    BrowserModule,
    BrowserAnimationsModule,
    FormsModule,
    HttpClientModule,
    HttpClientJsonpModule,
    DropDownsModule
  ],
  declarations: [
    AppComponent
  ],
  bootstrap: [
    AppComponent
  ]
})
export class AppModule { }
import { AppModule } from './ng.module';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';

const platform = platformBrowserDynamic();
platform.bootstrapModule(AppModule);

Streaming of Data

You can also bind the ComboBox to asynchronous data (observables) by using the async pipe.

The following example demonstrates how to utilize this approach. It starts with an empty observable, produces one random value each second, and emits values in batches of five.

import { Observable } from 'rxjs/Observable';
import 'rxjs/add/observable/interval';
import 'rxjs/add/operator/bufferCount';

@Component({
  selector: 'my-app',
  template: `
    <div class="example-config">
        <p>The selected value will disappear when the new data is set.</p>
        <p>New data will be available every 5 seconds (initially the ComboBox will be empty).</p>
    </div>
    <kendo-combobox [data]="listItems | async"></kendo-combobox>
  `
})
export class AppComponent {
  public listItems: Observable<string[]>;

  constructor() {
    this.listItems = Observable.interval(1000).map((x) =>  "New item " + x).bufferCount(5);
  }
}
In this article