Angular PrimeNG标签属性
Angular PrimeNG是一个开源框架,拥有丰富的原生Angular UI组件,可用于出色的造型,该框架可用于制作响应式网站,非常容易。在这篇文章中,我们将看到Angular PrimeNG标签属性。
标签组件用于创建用于对内容进行分类的标签。标签的内容由其value属性决定。
Angular PrimeNG标签属性:
- value。它是要在标签内显示的值。它接受一个字符串值,默认值为空。
- severity。它决定了该组件的严重程度。它可以是 “成功”、”信息”、”警告 “和 “危险 “中的一个。
- rounded:这是一个布尔属性,告诉人们标签的边角是否是圆的。默认值是false。
- icon:它是标签的图标,将显示在标签的值旁边。
- style。它是组件的内联风格。它是字符串类型的,默认值为空。
- styleClass。它是组件的风格类。它是字符串类型的,默认值为null。
语法:
<p-tag
value="..."
rounded= true || false
severity="..."
icon="...">
</p-tag>
创建Angular应用程序并安装模块:
第1步:使用以下命令创建一个Angular应用程序。
ng new appname
第2步:创建你的项目文件夹即appname后,使用以下命令移动到它。
cd appname
第3步在你给定的目录中安装PrimeNG。
npm install primeng --save
npm install primeicons --save
项目结构:完成安装后,项目结构将如下所示。
Project Structure
运行以下命令:
ng serve --open
例子1:这个例子显示了标签组件的value、styleClass、和severity属性的使用。
<h2 style="color: green">GeeksforGeeks</h2>
<h4>Angular PrimeNG Tag Properties</h4>
<p-tag
styleClass="mr-2"
value="MEARN STACK">
</p-tag>
<p-tag
styleClass="mr-2"
severity="success"
value="DSA">
</p-tag>
<p-tag
styleClass="mr-2"
severity="info"
value="REACT">
</p-tag>
<p-tag
styleClass="mr-2"
severity="warning"
value="ANGULAR">
</p-tag>
<p-tag
severity="danger"
value="NODE.JS">
</p-tag>
import { Component } from "@angular/core";
@Component({
selector: "app-root",
templateUrl: "./app.component.html",
styleUrls: ['./app.component.css']
})
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 { TagModule } from "primeng/tag";
@NgModule({
imports: [
BrowserModule,
BrowserAnimationsModule,
TagModule
],
declarations: [AppComponent],
bootstrap: [AppComponent],
})
export class AppModule { }
输出:
示例2:本例展示了使用rounded属性来使标签的边角变圆,以及使用icon属性将图标添加到标签中。
<h2 style="color: green">GeeksforGeeks</h2>
<h4>Angular PrimeNG Tag Properties</h4>
<p-tag
styleClass="mr-2"
[rounded]="true"
icon="pi pi-check"
value="MEARN STACK">
</p-tag>
<p-tag
styleClass="mr-2"
[rounded]="true"
icon="pi pi-hashtag"
severity="success"
value="DSA">
</p-tag>
<p-tag
styleClass="mr-2"
[rounded]="true"
icon="pi pi-code"
severity="info"
value="ANGULAR">
</p-tag>
<p-tag
severity="danger"
[rounded]="true"
icon="pi pi-circle"
value="NODE.JS">
</p-tag>
import { Component } from "@angular/core";
@Component({
selector: "app-root",
templateUrl: "./app.component.html",
styleUrls: ['./app.component.css']
})
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 { TagModule } from "primeng/tag";
@NgModule({
imports: [
BrowserModule,
BrowserAnimationsModule,
TagModule
],
declarations: [AppComponent],
bootstrap: [AppComponent],
})
export class AppModule { }
输出: