Angular PrimeNG 手风琴组件
Angular PrimeNG 是一个开源框架,具有丰富的原生 Angular UI 组件集,可用于出色的样式,并且该框架用于非常轻松地制作响应式网站。在本文中,我们将了解如何在 Angular PrimeNG 中使用 Accordion 组件。我们还将了解将在代码中使用的属性、样式以及它们的语法。
手风琴组件: It 用于在选项卡中显示一段自定义内容。
手风琴的属性:
- 多个:指定是否可以同时激活多个选项卡。它是布尔数据类型,默认值为 false。
- style:是组件的内联样式。它是字符串数据类型,默认值为空。
- styleClass:组件的样式类。它是字符串数据类型,默认值为 false。
- activeIndex:它是活动选项卡的索引。它接受任何数据类型,默认值为空。
- expandIcon:它是折叠标签的图标。它是字符串数据类型,默认值为 pi pi-fw pi-chevron-right。
- collapseIcon:展开标签的图标。它是字符串数据类型,默认值为 pi pi-fw pi-chevron-down。
AccordionTab 的属性:
- 标题: 它指定选项卡的标题。它是字符串数据类型,默认值为空。
- selected :它定义选项卡是否处于活动状态。它是布尔数据类型,默认值为 false。
- disabled :它定义是否可以选择选项卡。它是布尔数据类型,默认值为 false。
- transitionOptions:动画的过渡选项。它是字符串数据类型,默认值为 400ms 三次贝塞尔曲线(0.86, 0, 0.07, 1)。
- cache :它指定延迟加载的面板是否应避免在重新选择时再次加载。它是布尔数据类型,默认值为 true。
事件:
- onClose:这是一个通过单击标题触发的回调。
- onOpen:这是一个在选项卡展开时触发的回调。
造型:
- p-accordion:它是容器元素。
- p-accordion-header:它是选项卡的标题。
- p-accordion-content:它是选项卡的内容。
创建 Angular 应用程序和模块安装:
- 第 1 步:使用以下命令创建一个 Angular 应用程序。
ng new appname
- 第 2 步:创建项目文件夹(即 appname)后,使用以下命令移动到该文件夹。
cd appname
- 第 3 步:在给定目录中安装 PrimeNG。
npm install primeng --save
npm install primeicons --save
项目结构:它将如下所示:
示例 1:这是说明如何使用 Accordion 组件的基本示例。
app.component.html
GeeksforGeeks
PrimeNG Accordion component
Angular PrimeNG is a framework used with angular
to create components with great styling and this
framework is very easy to use and is used to make
responsive websites.
Angular PrimeNG is a framework used with angular
to create components with great styling and this
framework is very easy to use and is used to make
responsive websites.
Angular PrimeNG is a framework used with angular
to create components with great styling and this
framework is very easy to use and is used to make
responsive websites.
app.component.ts
import { Component } from "@angular/core";
@Component({
selector: "my-app",
templateUrl: "./app.component.html",
styleUrls: ["./app.component.scss"],
})
export class AppComponent {}
app.module.ts
import { NgModule } from "@angular/core";
import { BrowserModule } from "@angular/platform-browser";
import { BrowserAnimationsModule }
from "@angular/platform-browser/animations";
import { AppComponent } from "./app.component";
import { AccordionModule } from "primeng/accordion";
@NgModule({
imports: [BrowserModule,
BrowserAnimationsModule,
AccordionModule],
declarations: [AppComponent],
bootstrap: [AppComponent],
})
export class AppModule {}
app.component.html
GeeksforGeeks
PrimeNG Accordion component
Angular PrimeNG is a framework used with angular
to create components with great styling and this
framework is very easy to use and is used to make
responsive websites.
Angular PrimeNG is a framework used with angular
to create components with great styling and this
framework is very easy to use and is used to make
responsive websites.
Angular PrimeNG is a framework used with angular
to create components with great styling and this
framework is very easy to use and is used to make
responsive websites.
app.component.ts
import { Component } from "@angular/core";
@Component({
selector: "my-app",
templateUrl: "./app.component.html",
styleUrls: ["./app.component.scss"],
})
export class AppComponent {}
app.module.ts
import { NgModule } from "@angular/core";
import { BrowserModule } from "@angular/platform-browser";
import { BrowserAnimationsModule }
from "@angular/platform-browser/animations";
import { AppComponent } from "./app.component";
import { AccordionModule } from "primeng/accordion";
@NgModule({
imports: [BrowserModule,
BrowserAnimationsModule,
AccordionModule],
declarations: [AppComponent],
bootstrap: [AppComponent],
})
export class AppModule {}
app.component.ts
import { Component } from "@angular/core";
@Component({
selector: "my-app",
templateUrl: "./app.component.html",
styleUrls: ["./app.component.scss"],
})
export class AppComponent {}
app.module.ts
import { NgModule } from "@angular/core";
import { BrowserModule } from "@angular/platform-browser";
import { BrowserAnimationsModule }
from "@angular/platform-browser/animations";
import { AppComponent } from "./app.component";
import { AccordionModule } from "primeng/accordion";
@NgModule({
imports: [BrowserModule,
BrowserAnimationsModule,
AccordionModule],
declarations: [AppComponent],
bootstrap: [AppComponent],
})
export class AppModule {}
输出:
示例 2:在本示例中,我们将了解如何在 Accordion 组件中使用多个属性。
app.component.html
GeeksforGeeks
PrimeNG Accordion component
Angular PrimeNG is a framework used with angular
to create components with great styling and this
framework is very easy to use and is used to make
responsive websites.
Angular PrimeNG is a framework used with angular
to create components with great styling and this
framework is very easy to use and is used to make
responsive websites.
Angular PrimeNG is a framework used with angular
to create components with great styling and this
framework is very easy to use and is used to make
responsive websites.
app.component.ts
import { Component } from "@angular/core";
@Component({
selector: "my-app",
templateUrl: "./app.component.html",
styleUrls: ["./app.component.scss"],
})
export class AppComponent {}
app.module.ts
import { NgModule } from "@angular/core";
import { BrowserModule } from "@angular/platform-browser";
import { BrowserAnimationsModule }
from "@angular/platform-browser/animations";
import { AppComponent } from "./app.component";
import { AccordionModule } from "primeng/accordion";
@NgModule({
imports: [BrowserModule,
BrowserAnimationsModule,
AccordionModule],
declarations: [AppComponent],
bootstrap: [AppComponent],
})
export class AppModule {}
输出:
参考: https://primefaces.org/primeng/showcase/#/accordion