Open In App

Angular PrimeNG tag Component

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:

Styling:



 

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.




<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>




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 {}




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.




<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>




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 {}




import { Component } from '@angular/core';
  
@Component({
  selector: 'my-app',
  templateUrl: './app.component.html'
})
export class AppComponent {}

Output:

Reference: https://primefaces.org/primeng/showcase/#/tag


Article Tags :