New to Kendo UI for Angular? Start a free 30-day trial

Value Binding

The DropDownList value can either be a primitive (strings, numbers, or other) or a complex value (objects).

To set the value, apply any of the following approaches:

  • Use the value property. If the value is set through the value property, you have to hook up to the valueChange event and manually update the value of the value property.
  • Use the ngModel value binding. If the value is set by the ngModel value binding, the framework will automatically update the corresponding field from the model after the value of the component changes.
  • Use the formControlName value binding available in the Reactive forms. If the value is set by the formControlName value binding, the framework will automatically update the corresponding field from the form model after the value of the component changes.

The DropDownList does not support the simultaneous usage of the value property and the ngModel value binding.

When binding the DropDownList value, the component provides options for:

Primitive Values

If the DropDownList is bound to a dataset of primitives, its value will be a primitive of the same type.

Primitive data types include:

  • String
  • Number
  • Undefined
  • Null
Example
View Source
Change Theme:

Object Values

If the DropDownList is bound to a dataset of objects, its value will be an object of the same type.

When the selected item is an object, always specify valueField. If you do not set a value for the field, the DropDownList will compare the items by reference, which may complicate debugging. For example, the selected value will not be applied, if it does not reference the exact passed data object.

Example
View Source
Change Theme:

Primitive Values from Object Fields

If the DropDownList is bound to a dataset of objects and the valuePrimitive property is set to true, the value of the component will be extracted from the valueField of the objects.

Example
View Source
Change Theme:

Invalid Value Errors

If the value which is assigned through the [value] or [(ngModel)] inputs does not match the expected type, the DropDownList throws a JavaScript error.

In the following example, the component has both its [valueField] and [textField] specified, which implies that the [data] will contain objects. Because the [valuePrimitive] is not explicitly set to true, the DropDownList expects an object value. Instead, a number is provided and, as a result, a JavaScript exception occurs.
Example
View Source
Change Theme:

To fix the JavaScript issue, either:

  • Change the value type, or
  • Update the settings of the component.

The following table lists the valid configuration scenarios.

Value[Data][ValuePrimitive]
primitiveprimitivesNot set (automatically calculated as true)
objectobjectsNot set (automatically calculated as false)
primitiveobjectstrue (manually set by the developer)