Angular PrimeNG Badge Severities

Angular PrimeNG Badge Severities

Angular PrimeNG是一个开源框架,拥有丰富的原生Angular UI组件,可以用来做很好的造型,这个框架用来制作响应式网站非常方便。本文将向我们展示如何在Angular PrimeNG中使用Badge Severities。

徽章组件将文本表示为一个状态指示器,或将数字表示为一个徽章。作为严重性等级,提供了许多颜色选项。当一个元素被利用时,使用严重性属性来应用一个严重性。有4个严重程度的值。成功,信息,警告,危险_。

语法:

<p-badge
     [value]="..."
     size="..."
     severity="...">
</p-badge>

Angular PrimeNG Badge的严重性属性:

  • value。它用于定义在徽章中显示的值。它是字符串数据类型,默认值为空。
  • severity。它用于设置徽章的严重性类型。它是字符串数据类型,默认值为空。
  • size。它用于定义徽章的大小,有效的选项是“大”“xlarge”。它是字符串数据类型,默认值为空。

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

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

ng new appname

第2步:创建你的项目文件夹即appname后,使用以下命令移动到它。

cd appname

第3步:在你给定的目录中安装PrimeNG。

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

项目结构:它将看起来像如下。

Angular PrimeNG Badge Severities

  • 运行下面的命令可以看到输出。
ng serve --open

示例1:下面是说明使用**Angular PrimeNG Badge Severity的示例代码。

<div style="text-align: center">
    <h2 style="color: green">GeeksforGeeks</h2>
    <h5>Angular PrimeNG Badge Severity</h5>
  
    <p-badge [value]="5" 
             size="xlarge" 
             styleClass="p-mr-5" 
             severity="danger">
    </p-badge>
  
    <i class="pi pi-bookmark" 
       style="font-size: 2.4rem" pBadge 
       value="4" 
       severity="success">
    </i>
</div>
import { Component } from "@angular/core";
  
@Component({
   selector: "app-root",
   templateUrl: "./app.component.html"
})
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 { ButtonModule } from "primeng/button";
import { BadgeModule } from "primeng/badge";
  
@NgModule({
 imports: [
   BrowserModule,
   BrowserAnimationsModule,
   BadgeModule,
   ButtonModule,
   BadgeModule
 ],
 declarations: [AppComponent],
 bootstrap: [AppComponent]
})
export class AppModule {}

输出:

Angular PrimeNG Badge Severities

例子2:下面是另一个例子代码,说明了**Angular PrimeNG Badge Severity的使用。

<div style="text-align: center">
    <h2 style="color: green">GeeksforGeeks</h2>
    <h5>Angular PrimeNG Badge Severity</h5>
  
    <p-badge [value]="6" 
             size="xlarge" 
             styleClass="p-mr-5" 
             severity="warning">
    </p-badge>
  
    <i class="pi pi-code" 
       style="font-size: 2.4rem" pBadge 
       value="7" 
       severity="info">
    </i>
</div>
import { Component } from "@angular/core";
  
@Component({
   selector: "app-root",
   templateUrl: "./app.component.html"
})
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 { ButtonModule } from "primeng/button";
import { BadgeModule } from "primeng/badge";
  
@NgModule({
 imports: [
   BrowserModule,
   BrowserAnimationsModule,
   BadgeModule,
   ButtonModule,
   BadgeModule
 ],
 declarations: [AppComponent],
 bootstrap: [AppComponent]
})
export class AppModule {}

输出:

Angular PrimeNG Badge Severities

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程