# Data Binding

The Menu enables you to bind it to an array of [`MenuItem`](https://www.telerik.com/kendo-angular-ui/components/menus/api/menuitem) objects by using its [`items`](https://www.telerik.com/kendo-angular-ui/components/menus/api/menucomponent#items) property.

Each `MenuItem` may contain an [`items`](https://www.telerik.com/kendo-angular-ui/components/menus/api/menuitem#items) array of child items.

## Binding to Local Data

The following example demonstrates how to bind the Menu to local data.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/menus/data-binding/local/source.txt)

## Binding to Remote Data

The following example demonstrates how to bind the Menu to remote data.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/menus/data-binding/remote/source.txt)

## Built-in Directives

To simplify data binding and minimize boilerplate code, the Menu delivers the following built-in directives:

* `kendoMenuHierarchyBinding`—Handles the conversion to array of [`MenuItems`](https://www.telerik.com/kendo-angular-ui/components/menus/api/menuitem) of hierarchical data.
* `kendoMenuFlatBinding`—Handles the conversion to array of [`MenuItems`](https://www.telerik.com/kendo-angular-ui/components/menus/api/menuitem) of flat data.

### Hierarchy Binding

The [`kendoMenuHierarchyBinding`](https://www.telerik.com/kendo-angular-ui/components/menus/api/hierarchybindingdirective) directive simplifies the binding to hierarchical data. To use it, bind the directive to the data and set the [`childrenField`](https://www.telerik.com/kendo-angular-ui/components/menus/api/hierarchybindingdirective#childrenfield), [`textField`](https://www.telerik.com/kendo-angular-ui/components/menus/api/hierarchybindingdirective#textfield), etc. properties to the fields from the data that should be used to create the [`MenuItems`](https://www.telerik.com/kendo-angular-ui/components/menus/api/menuitem). If a property is set to a array of fields, each hierarchical level uses the field that corresponds to the same index in the array, or the last item in the array. If a property is set to a field then it will be used for all levels.

The following example demonstrates using the `kendoMenuHierarchyBinding` directive.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/menus/data-binding/hierarchy/source.txt)

### Flat Binding

The [`kendoMenuFlatBinding`](https://www.telerik.com/kendo-angular-ui/components/menus/api/flatbindingdirective) directive simplifies the binding to flat data. To use it, bind the directive to the data and set the [`idField`](https://www.telerik.com/kendo-angular-ui/components/menus/api/flatbindingdirective#idfield) and [`parentIdField`](https://www.telerik.com/kendo-angular-ui/components/menus/api/flatbindingdirective#parentidfield) to the fields from the data that represent the relation between parent and child nodes.

The following example demonstrates using the `kendoMenuFlatBinding` directive.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/menus/data-binding/flat/source.txt)

### Updating the binding directives

If you modify individual fields or items in place, the binding directive does not detect the change and the Menu stays unchanged. Call the directive's `rebind()` method to refresh the Menu.

The following example demonstrates how to update Menu items on the fly by modifying the underlying data and calling the `rebind()` method of the binding directive.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/menus/data-binding/update/source.txt)

## Suggested Links

* [API Reference of the Menu](https://www.telerik.com/kendo-angular-ui/components/menus/api)
