Angular PrimeNG Fieldset组件
Angular PrimeNG是一个开源框架,它有丰富的原生Angular UI组件,可以用来做很好的造型,这个框架被用来做响应式网站,非常方便。在这篇文章中,我们将了解如何在Angular PrimeNG中使用Fieldset组件。我们还将学习属性、事件和造型,以及代码中使用的语法。
Fieldset组件:它是一个分组组件,它需要一个标题以及与该标题相关的一些内容,有一个切换功能。
属性:
- 图例。它是字段集的标题文本。它是字符串数据类型,默认值为空。
- toggleable:它指定了是否可以通过点击图例来切换内容。它是布尔数据类型,默认值是false。
- collapsed:它定义了内容的默认可见性状态。它是布尔数据类型,默认值为false。
- style。它是一个字段集的内联样式。它是字符串数据类型,默认值为空。
- styleClass。它是字段集的风格类。它是字符串数据类型,默认值为空。
- transitionOptions。这是动画的过渡选项。它是字符串数据类型,默认值是400ms cubic-bezier(0.86, 0, 0.07, 1)。
Event:
- onBeforeToggle。它是一个回调,在内容切换前被触发。
- onAfterToggle。它是一个回调,在内容切换后被触发。
Styling:
- p-fieldset。它是fieldet元素。
- p-fieldset-toggleable。它是可切换的字段集元素。
- p-fieldset-legend。它是图例元素。
- p-fieldset-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 Fieldset Component</h5>
<p-fieldset legend="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-fieldset>
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 { FieldsetModule } from "primeng/fieldset";
@NgModule({
imports: [BrowserModule,
BrowserAnimationsModule,
FieldsetModule],
declarations: [AppComponent],
bootstrap: [AppComponent],
})
export class AppModule {}
输出:
例子2:在这个例子中,我们将知道如何在字段集组件中使用toggleable属性。
<h2>GeeksforGeeks</h2>
<h5>PrimeNG Fieldset Component</h5>
<p-fieldset legend="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-fieldset>
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 { FieldsetModule } from "primeng/fieldset";
@NgModule({
imports: [BrowserModule,
BrowserAnimationsModule,
FieldsetModule],
declarations: [AppComponent],
bootstrap: [AppComponent],
})
export class AppModule {}
输出: