Angular PrimeNG徽章的尺寸

Angular PrimeNG徽章的尺寸

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

徽章组件将文本作为状态指示器或数字作为徽章表示。size属性支持“large”“xlarge”作为默认尺寸的潜在替代品,它被用来改变徽章尺寸。目前,尺寸只在组件模式下相关。

语法:

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

Angular PrimeNG徽章的尺寸属性:

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

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

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

ng new appname

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

cd appname

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

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

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

Angular PrimeNG徽章的尺寸

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

实例1:下面是说明使用**Angular PrimeNG徽章尺寸的示例代码。

<div style="text-align: center">
  <h2 style="color: green">GeeksforGeeks</h2>
  <h5>Angular PrimeNG Badge Sizes</h5>
  
  <div class="badges">
    <p-badge [value]="'9'" 
             styleClass="mr-3" 
             severity="success"> 
    </p-badge>
  
    <p-badge [value]="'8'" 
             size="large" 
             severity="warning"> 
    </p-badge>
  </div>
</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],
  declarations: [AppComponent],
  bootstrap: [AppComponent],
})
export class AppModule {}

输出:

Angular PrimeNG徽章的尺寸

示例2:下面是另一个说明**Angular PrimeNG徽章尺寸的示例代码。

<div style="text-align: center">
  <h2 style="color: green">GeeksforGeeks</h2>
  <h5>Angular PrimeNG Badge Sizes</h5>
  
  <div class="badges">
    <p-badge [value]="'9'" 
             styleClass="mr-3" 
             size="large" 
             severity="info">
    </p-badge>
  
    <p-badge [value]="'5'" 
             size="xlarge"
             severity="danger"> 
    </p-badge>
  </div>
</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],
  declarations: [AppComponent],
  bootstrap: [AppComponent],
})
export class AppModule {}

输出:

Angular PrimeNG徽章的尺寸

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程