To set the value, apply any of the following approaches:
- Use the
valueproperty. If the value is set through the
valueproperty, you have to hook up to the
valueChangeevent and manually update the value of the
- Use the
ngModelvalue binding. If the value is set by the
ngModelvalue binding, the framework will automatically update the corresponding field from the model after the value of the component changes.
- Use the
formControlNamevalue binding, which is available in the Reactive forms. If the value is set by the
formControlNamevalue binding, the framework will automatically update the corresponding field from the form model after the value of the component changes.
- The ComboBox does not support the simultaneous usage of the
valueproperty and the
- The ComboBox does not support values, which contain
\nnew line characters. The regular
inputHTML DOM element, which the ComboBox uses internally treats
\nas a regular whitespace. Therefore, when the component compares the value of the
inputelement with the data item that is selected by the user, the two values differ. The value of the
inputelement is actually not present in the data of the component and the ComboBox does not recognize it. To handle such issues, map the incoming data so that it contains regular whitespaces only.
When binding the ComboBox, the component provides options for:
- Using primitive values (string, number, or other)
- Using object values
- Using primitive values from object fields
- Using custom values
- Handling invalid value errors
- Handling unresolved text
If the ComboBox is bound to a dataset of primitives, its value will be a primitive of the same type.
Primitive data types include:
If the ComboBox 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 ComboBox 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
If the value, which is assigned through the
In the following example, the component has both its
[textField] specified, which implies that the
[data] will contain objects. Because the
[valuePrimitive] is not explicitly set to
- Change the value type, or
- Update the settings of the component.
The following table lists the valid configuration scenarios.
|primitive||primitives||Not set (automatically calculated as |
|object||objects||Not set (automatically calculated as |
The text value, which is assigned through the
[(ngModel)] inputs and which is not found in the dataset will not be resolved. Such values also include object values that contain the
The following example demonstrates how to merge the assigned value with the dataset and ensure that its text will be properly extracted and displayed.