Angular PrimeNG卡片组件
Angular PrimeNG是一个开源框架,它拥有丰富的原生Angular UI组件,这些组件被用来做伟大的造型,这个框架被用来制作响应式网站,非常容易。在这篇文章中,我们将了解如何在Angular PrimeNG中使用卡片组件。我们还将学习属性、造型以及在代码中使用的语法。
卡片组件:卡片用于显示灵活和可扩展的内容容器。
属性:
- header。它指定了卡片的标题。它是字符串数据类型,默认值为空。
- subheader。它指定了卡片的副标题。它是字符串数据类型,默认值为空。
- style。它用于设置组件的内联风格。它的数据类型为字符串,默认值为空。
- styleClass。它用于设置组件的风格类别。它的数据类型为字符串,默认值为空。
Styling:
- p-card。它是容器元素。
- p-card-读者。它是标题元素。
- p-card-subheader :它是副标题元素。
- p-card-content。它是卡片的内容。
- p-card-footer:它是卡片的页脚。
创建Angular应用程序和模块安装。
- 第1步:使用以下命令创建一个Angular应用程序。
ng new appname
- 第2步:在创建你的项目文件夹即appname后,使用以下命令移动到它。
cd appname
- 第3步:在你给定的目录中安装PrimeNG。
npm install primeng --save
npm install primeicons --save
项目结构。它将看起来像以下。
例子1:这是一个基本的例子,说明了如何使用卡片组件。****
<h2>GeeksforGeeks</h2>
<p-card header="Angular PrimeNG Card component">
<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-card>
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 { CardModule } from "primeng/card";
@NgModule({
imports: [BrowserModule,
BrowserAnimationsModule,
CardModule],
declarations: [AppComponent],
bootstrap: [AppComponent],
})
export class AppModule {}
输出:

例子2:在这个例子中,我们将知道如何在卡片组件中使用subheader属性。
<p-card header='GeeksforGeeks' subheader="Angular PrimeNG Card component">
<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-card>
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 { CardModule } from 'primeng/card';
@NgModule({
imports: [BrowserModule,
BrowserAnimationsModule,
CardModule],
declarations: [AppComponent],
bootstrap: [AppComponent]
})
export class AppModule {}
输出:

极客教程