Меню
PrimeNG/Menu (opens in a new tab)
Меню - это компонент навигации/команд, который поддерживает динамическое и статическое позиционирование.
С чего начать
Подключите модуль
import { MenuModule } from 'primeng/menu';
В .ts файле
import { Component, OnInit } from '@angular/core';
import { MenuItem } from 'primeng/api';
import { MessageService } from 'primeng/api';
@Component({
selector: 'app-prime-menu',
templateUrl: './prime-menu.component.html',
styleUrls: ['./prime-menu.component.scss'],
providers: [MessageService]
})
export class PrimeMenuComponent implements OnInit {
items: MenuItem[] = [];
constructor(private messageService: MessageService) { }
ngOnInit(): void {
this.items = [{
label: 'Options',
items: [{
label: 'Update',
icon: 'pi pi-refresh',
command: () => {
this.update();
}
},
{
label: 'Delete',
icon: 'pi pi-times',
command: () => {
this.delete();
}
}
]
},
{
label: 'Navigate',
items: [{
label: 'Angular',
icon: 'pi pi-external-link',
url: 'http://angular.io'
},
{
label: 'Router',
icon: 'pi pi-upload',
routerLink: '/fileupload'
}
]
}
];
}
update() {
this.messageService.add({ severity: 'success', summary: 'Success', detail: 'Data Updated' });
}
delete() {
this.messageService.add({ severity: 'warn', summary: 'Delete', detail: 'Data Deleted' });
}
}
Встройте компонент с помощью тэга p-menu.
Для отображения всплывающих сообщений разместите в теле страницы следующий код:
Basic
Overlay
Свойства
Name | Type | Default | Description |
---|---|---|---|
model | array | null | An array of menuitems. |
popup | boolean | false | Defines if menu would displayed as a popup. |
style | string | null | Inline style of the component. |
styleClass | string | null | Style class of the component. |
appendTo | any | null | Target element to attach the overlay, valid values are "body" or a local ng-template variable of another element (note: use binding with brackets for template variables, e.g. [appendTo]="mydiv" for a div element having #mydiv as variable name). |
baseZIndex | number | 0 | Base zIndex value to use in layering. |
autoZIndex | boolean | true | Whether to automatically manage layering. |
showTransitionOptions | string | .12s cubic-bezier(0, 0, 0.2, 1) | Transition options of the show animation. |
hideTransitionOptions | string | .1s linear | Transition options of the hide animation. |
События
Name | Parameters | Description |
---|---|---|
onShow | event: Event object | Callback to invoke when overlay menu is shown. |
onHide | event: Event object | Callback to invoke when overlay menu is hidden. |
Методы
Name | Parameters | Description |
---|---|---|
toggle | event: browser event | Toggles the visibility of the popup menu. |
show | event: browser event | Displays the popup menu. |
hide | - | Hides the popup menu. |
Стилизация
Name | Element |
---|---|
p-menu | Container element. |
p-menu-list | List element. |
p-menuitem | Menuitem element. |
p-menuitem-text | Label of a menuitem. |
p-menuitem-icon | Icon of a menuitem. |