Angular PrimeNG tag Component - GeeksforGeeks

08 Sep, 2021
Angular PrimeNG is an open-source framework with a rich set of native Angular UI components that are used for great styling and this framework is used to make responsive websites with very much ease. In this article, we will know how to use the tag component in Angular PrimeNG.
tag component: It is used to make a tag in order to categorize the content.
Properties:
value: It specifies the value to display inside the tag. It is of string data type, the default value is null.
severity: It specifies the severity type of the tag. It is of string data type, the default value is null.
rounded: It specifies whether the corners of the tag are rounded or not. It is of the boolean data type, the default value is false.
icon: It sets the icon of the tag to display next to the value. It is of string data type, the default value is null.
style: It specifies the inline style of the component. It is of object data type, the default value is null.
styleClass: It specifies the style class of the component. It is of string data type, the default value is null.
Styling:
p-tag: It is a tag element.
p-tag-rounded: It is used to make the rounded shaped elements.
p-tag-icon: It is a tag icon.
p-tag-value: It is a value of the tag.
 
Creating Angular application & module installation:
Step 1: Create an Angular application using the following command.
ng new appname
Step 2: After creating your project folder i.e. appname, move to it using the following command.
cd appname
Step 3: Install PrimeNG in your given directory.
npm install primeng --save
npm install primeicons --save
Project Structure: After complete installation, it will look like the following:
 
Example 1: This is the basic example that shows how to use the tag component.
app.component.html
<h2>GeeksforGeeks</h2><h5>PrimeNg Tag Component</h5><p-tag styleClass="p-mr-2" value="Tag1"        icon="pi pi-check"></p-tag><p-tag styleClass="p-mr-2" value="Tag2"        icon="pi pi-bars" severity="success"></p-tag><p-tag styleClass="p-mr-2" value="Tag3"        icon="pi pi-info" severity="info"></p-tag><p-tag styleClass="p-mr-2" value="Tag4"        icon="pi pi-times" severity="danger"></p-tag><p-tag styleClass="p-mr-2" value="Tag5"        icon="pi pi-thumbs-up" severity="warning"></p-tag>
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 { TagModule } from 'primeng/tag';  @NgModule({  imports: [BrowserModule,               BrowserAnimationsModule,             TagModule],  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 {}
Output:
Example 2: In this example, we will use the rounded property in the tag component.
app.component.html
<h2>GeeksforGeeks</h2><h5>PrimeNg Tag Component</h5><p-tag styleClass="p-mr-2" value="Check" rounded='true'        icon="pi pi-check" severity="success"></p-tag><p-tag styleClass="p-mr-2" value="Info" rounded='true'        icon="pi pi-info"></p-tag><p-tag styleClass="p-mr-2" value="Bars" rounded='true'        icon="pi pi-bars" severity="danger"></p-tag><p-tag styleClass="p-mr-2" value="Thumbs Up" rounded='true'        icon="pi pi-thumbs-up" severity="warning"></p-tag><p-tag styleClass="p-mr-2" value="Cross" rounded='true'        icon="pi pi-times" severity="info"></p-tag>
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 { TagModule } from 'primeng/tag';  @NgModule({  imports: [BrowserModule,               BrowserAnimationsModule,             TagModule],  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 {}
Output:
Reference: https://primefaces.org/primeng/showcase/#/tag
Angular-PrimeNG
AngularJS
Web Technologies
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Angular PrimeNG Dropdown Component
Angular PrimeNG Calendar Component
Angular PrimeNG Messages Component
Angular 10 (blur) Event
How to make a Bootstrap Modal Popup in Angular 9/8 ?
Remove elements from a JavaScript Array
Installation of Node.js on Linux
Convert a string to an integer in JavaScript
How to fetch data from an API in ReactJS ?
How to insert spaces/tabs in text using HTML/CSS?