Angular PrimeNG Menubar组件

Angular PrimeNG Menubar组件

Angular PrimeNG是一个开源框架,它拥有丰富的原生Angular UI组件,这些组件被用来做伟大的造型,这个框架被用来制作响应式网站,非常容易。在这篇文章中,我们将了解如何在Angular PrimeNG中使用Menubar组件。我们还将学习属性、造型以及在代码中使用的语法。

Menubar组件:它被用来制作一个水平条形式的菜单列表。

属性:

  • model。它是一个菜单项的数组。它接受数组数据类型作为输入,默认值为空。
  • style。它是组件的一个内联样式。它的数据类型为字符串,默认值为空。
  • styleClass。它用于设置组件的风格类别。它的数据类型为字符串,默认值为空。
  • baseZIndex。它用于设置分层中使用的基础ZIndex值。它接受数字数据类型作为输入,默认值为0。
  • autoZIndex。它用于指定是否自动管理分层。它接受布尔数据类型作为输入,默认值为true。
  • autoDisplay。它用于指定是否在鼠标移动时显示根子菜单。它接受布尔数据类型作为输入,默认值为false。

样式 :

  • p-menubar。它是容器元素。
  • p-menu-list。它是一个列表元素。
  • p-menuitem。它是menuitem元素。
  • p-menuitem-text : 它是一个menuitem的标签。
  • p-menuitem-icon。它是一个菜单项的图标。
  • p-submenu-icon。它是一个子菜单的箭头图标。

创建Angular应用程序和模块安装。

  • 第1步:使用以下命令创建一个Angular应用程序。
ng new appname
  • 第2步:在创建你的项目文件夹即appname后,使用以下命令移动到它。
cd appname
  • 第3步:在你给定的目录中安装PrimeNG。
npm install primeng --save
npm install primeicons --save

项目结构:它将看起来像如下。

Angular PrimeNG Menubar组件

例子:这是一个基本的例子,说明了如何使用Menubar组件。

<h2>GeeksforGeeks</h2>
<h5>PrimeNG MenuBar Component</h5>
<p-menubar [model]="gfg"></p-menubar>
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } 
    from '@angular/platform-browser/animations';
  
import { AppComponent } from './app.component';
import { MenubarModule } from 'primeng/menubar';
@NgModule({
  imports: [BrowserModule, 
              BrowserAnimationsModule, 
            MenubarModule],
  declarations: [AppComponent],
  bootstrap: [AppComponent]
})
export class AppModule {}
import { Component } from '@angular/core';
import { MenuItem } from 'primeng/api';
  
@Component({
  selector: 'my-app',
  templateUrl: './app.component.html'
})
export class AppComponent {
  gfg: MenuItem[];
  
  ngOnInit() {
    this.gfg = [
      {
        label: 'HTML',
        items: [
          {
            label: 'HTML 1'
          },
          {
            label: 'HTML 2'
          }
        ]
      },
      {
        label: 'Angular',
  
        items: [
          {
            label: 'Angular 1'
          },
          {
            label: 'Angular 2'
          }
        ]
      }
    ];
  }
}

输出:

Angular PrimeNG Menubar组件

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程