Angular PrimeNG面板组件
Angular PrimeNG是一个开源框架,它拥有丰富的原生Angular UI组件,这些组件被用来做伟大的造型,这个框架被用来制作响应式网站,非常容易。在这篇文章中,我们将了解如何在Angular PrimeNG中使用面板组件。我们还将学习属性、事件和造型,以及在代码中使用的语法。
面板组件:它允许我们制作一个包含头和一些与该头相关的内容的元素。
属性:
- header。它是面板的标题文本。它是字符串数据类型,默认值为空。
- toggleable。它定义了面板的内容是否可以被展开和折叠。它是布尔数据类型,默认值是false。
- collapsed:它定义了面板内容的初始状态。它是布尔数据类型,默认值是false。
- style。它是组件的内联样式。它是字符串数据类型,默认值为空。
- styleClass。它是组件的风格类。它是字符串数据类型,默认值为空。
- expandIcon:它是切换按钮的扩展图标。它是字符串数据类型,默认值是pi-plus。
- collapseIcon:它是切换按钮的折叠图标。它是字符串数据类型,默认值是pi pi-minus。
- showHeader。它指定一个面板的标题是否不能显示。它是布尔数据类型,默认值为true。
- transitionOptions。这是动画的过渡选项。它是字符串数据类型,默认值是400ms cubic-bezier(0.86, 0, 0.07, 1)。
- toggler:它指定了是否用toggler元素来切换面板的内容。它是字符串数据类型,默认值是一个图标。
事件:
- onBeforeToggle。它是一个回调,在内容切换前被触发。
- onAfterToggle。它是一个回调,在内容切换后被触发。
样式:
- p-panel : 它是容器元素。
- p-panel-titlebar:它是标题部分。
- p-panel-title。它是面板的标题文本。
- p-panel-titlebar-toggler:它是切换图标。
- p-panel-content。这是该面板的内容。
创建Angular应用程序和模块安装。
- 第1步:使用以下命令创建一个Angular应用程序。
ng new appname
- 第2步:在创建你的项目文件夹即appname后,使用以下命令移动到它。
cd appname
- 第3步:在你给定的目录中安装PrimeNG。
npm install primeng --save
npm install primeicons --save
项目结构。它将看起来像以下。
例子1:这是一个基本的例子,说明了如何使用面板组件。
<h2>GeeksforGeeks</h2>
<h5>PrimeNG Panel Component</h5>
<p-panel header="Angular PrimeNG">
<p>
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.
</p>
</p-panel>
import { Component } from '@angular/core';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent {}
import { NgModule } from "@angular/core";
import { BrowserModule } from "@angular/platform-browser";
import { BrowserAnimationsModule }
from "@angular/platform-browser/animations";
import { AppComponent } from "./app.component";
import { PanelModule } from "primeng/panel";
@NgModule({
imports: [BrowserModule,
BrowserAnimationsModule,
PanelModule],
declarations: [AppComponent],
bootstrap: [AppComponent],
})
export class AppModule {}
输出:
例子2:在这个例子中,我们将知道如何在面板组件中使用toggleable属性。
<h2>GeeksforGeeks</h2>
<h5>PrimeNG Panel Component</h5>
<p-panel header="Angular PrimeNG" toggleable="true">
<p>
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.
</p>
</p-panel>
import { Component } from '@angular/core';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent {}
import { NgModule } from "@angular/core";
import { BrowserModule } from "@angular/platform-browser";
import { BrowserAnimationsModule }
from "@angular/platform-browser/animations";
import { AppComponent } from "./app.component";
import { PanelModule } from "primeng/panel";
@NgModule({
imports: [BrowserModule,
BrowserAnimationsModule,
PanelModule],
declarations: [AppComponent],
bootstrap: [AppComponent],
})
export class AppModule {}
输出: