Angular PrimeNG徽章的定位徽章
Angular PrimeNG是一个开源框架,它有丰富的原生Angular UI组件,用来做很好的造型,这个框架用来做响应式网站,非常方便。本文将向我们展示如何在Angular PrimeNG中使用Badge Positioned Badge。
徽章组件将文本作为一个状态指示器或数字作为一个徽章表示。通过使用pBadge指令,徽章可以被定位在一个图标的右上方。
语法:
<i pBadge
class="...."
style="...."
value="...."
sevirity="...">
</i>
Angular PrimeNG徽章定位的徽章属性:
- value。它用于定义在徽章中显示的值。它是字符串数据类型,默认值为空。
- class。它是一个用空格分隔的列表,用于指定要渲染的图标的名称。
- severity。它用于设置徽章的严重性类型。它是字符串数据类型,默认值为空。
- style。它用于设置组件的内联风格。它是一个对象数据类型,默认值为空。
创建Angular应用程序和模块安装。
第1步:使用以下命令创建一个Angular应用程序。
ng new appname
第2步:创建你的项目文件夹即appname后,使用以下命令移动到它。
cd appname
第3步:在你给定的目录中安装PrimeNG。
npm install primeng --save
npm install primeicons --save
项目结构:它将看起来像如下。
- 运行下面的命令可以看到输出。
ng serve --open
示例1:下面是说明使用**Angular PrimeNG Badge定位徽章的示例代码。
<div style="text-align: center">
<h2 style="color: green">GeeksforGeeks</h2>
<h5>Angular PrimeNG Positioned Badge</h5>
<i class="pi pi-database
mr-4 p-text-secondary" pBadge
style="font-size: 3rem"
value="1"
severity="danger">
</i>
<i class="pi pi-bookmark-fill
p-text-secondary" pBadge
style="font-size: 3rem"
[value]="'10+'"
severity="warning">
</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
],
declarations: [AppComponent],
bootstrap: [AppComponent],
})
export class AppModule {}
输出:
例子2:下面是另一个说明**Angular PrimeNG Badge Positioned Badge的例子代码。
<div style="text-align: center">
<h2 style="color: green">GeeksforGeeks</h2>
<h5>Angular PrimeNG Positioned Badge</h5>
<i class="pi pi-whatsapp
mr-5 p-text-secondary" pBadge
style="font-size: 3rem"
value="10+"
severity="success">
</i>
<i class="pi pi-slack
p-text-secondary" pBadge
style="font-size: 3rem"
[value]="'50+'"
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
],
declarations: [AppComponent],
bootstrap: [AppComponent],
})
export class AppModule {}
输出: