📜  Angular PrimeNG 徽章组件

📅  最后修改于: 2022-05-13 01:56:26.983000             🧑  作者: Mango

Angular PrimeNG 徽章组件

Angular PrimeNG 是一个开源框架,具有丰富的原生 Angular UI 组件集,可用于出色的样式,并且该框架用于非常轻松地制作响应式网站。在本文中,我们将了解如何在 Angular PrimeNG 中使用 Badge 组件。

徽章组件:用于将文本表示为状态指示器或将数字表示为徽章。

特性:

  • value :用于定义要在徽章内显示的值。它是字符串数据类型,默认值为空。
  • 严重性:用于设置徽章的严重性类型。它是字符串数据类型,默认值为空。
  • size :用于定义徽章的大小,有效选项为“large”和“xlarge”。它是字符串数据类型,默认值为空。
  • style :用于设置组件的 Inline 样式。它是对象数据类型,默认值为空。
  • styleClass :用于定义组件的样式类。它是字符串数据类型,默认值为空。

造型:

  • p-badge :它是一个徽章元素。
  • p-overlay-badge :它是一个包装徽章及其目标。
  • p-badge-dot :它是一个没有价值的徽章元素。
  • p-badge-success:它是具有成功严重性的徽章元素。
  • p-badge-info:它是一个带有信息严重性的徽章元素。
  • p-badge-warning:这是一个带有警告严重性的徽章元素。
  • p-badge-danger:危险严重程度的标志元素。
  • p-badge-lg:是一个大的徽章元素。
  • p-badge-xl:超大徽章元素。

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

  • 第 1 步:使用以下命令创建一个 Angular 应用程序。

    ng new appname
  • 第 2 步:创建项目文件夹(即 appname)后,使用以下命令移动到该文件夹。

    cd appname
  • 第 3 步:在给定目录中安装 PrimeNG。

    npm install primeng --save
    npm install primeicons --save

项目结构:它将如下所示。

示例 1:这是展示如何使用徽章组件的基本示例。

app.component.html

GeeksforGeeks

PrimeNG Badge Component
              


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 { BadgeModule } from "primeng/badge";
  
@NgModule({
  imports: [BrowserModule, 
              BrowserAnimationsModule, 
            BadgeModule],
  declarations: [AppComponent],
  bootstrap: [AppComponent],
})
export class AppModule {}


app.component.ts
import { Component } from "@angular/core";
  
@Component({
  selector: "my-app",
  templateUrl: "./app.component.html",
})
export class AppComponent {}


app.component.html

GeeksforGeeks

PrimeNG Badge Component


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 { ButtonModule } from "primeng/button";
import { BadgeModule } from "primeng/badge";
  
@NgModule({
  imports: [
    BrowserModule,
    BrowserAnimationsModule,
    BadgeModule,
    ButtonModule,
    BadgeModule,
  ],
  declarations: [AppComponent],
  bootstrap: [AppComponent],
})
export class AppModule {}


app.compnent.ts
import { Component } from '@angular/core';
  
@Component({
  selector: 'my-app',
  templateUrl: './app.component.html'
})
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 { BadgeModule } from "primeng/badge";
  
@NgModule({
  imports: [BrowserModule, 
              BrowserAnimationsModule, 
            BadgeModule],
  declarations: [AppComponent],
  bootstrap: [AppComponent],
})
export class AppModule {}

app.component.ts

import { Component } from "@angular/core";
  
@Component({
  selector: "my-app",
  templateUrl: "./app.component.html",
})
export class AppComponent {}

输出:

示例 2:在本示例中,我们将了解如何在消息组件中插入图标。

app.component.html

GeeksforGeeks

PrimeNG Badge Component

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 { ButtonModule } from "primeng/button";
import { BadgeModule } from "primeng/badge";
  
@NgModule({
  imports: [
    BrowserModule,
    BrowserAnimationsModule,
    BadgeModule,
    ButtonModule,
    BadgeModule,
  ],
  declarations: [AppComponent],
  bootstrap: [AppComponent],
})
export class AppModule {}

应用程序组件.ts

import { Component } from '@angular/core';
  
@Component({
  selector: 'my-app',
  templateUrl: './app.component.html'
})
export class AppComponent {}

输出:

参考: https://primefaces.org/primeng/showcase/#/badge