Creating programmatic menus using the MenuModel API
PrimeNG provides a MenuModel
API, which will be shared by all menu components to specify menu items and sub-menus. The core item of the MenuModel
API is the MenuItem
class with options such as label
, icon
, url
, child menu items with the items
option, and so on.
Let's take an example of the Menu component to represent a common toolbar user interface. The Menu component is binding an array of the MenuItem
classes as items through the model
property as follows:
<p-menu [model]="items"></p-menu>
MenuItem
is the key item in the MenuModel
API. It has the following list of properties. Each property is described with the type, default value, and its description:
Name | Type | Default | Description |
|
|
| Text of the item. |
|
|
| Icon of the item. |
|
|
| Callback to execute when the item is clicked. |
|
|
| External link to navigate when the item is clicked. |
|
|
| RouterLink definition for internal navigation... |