7

Angular PrimeNG Tag Icons

 1 year ago
source link: https://www.geeksforgeeks.org/angular-primeng-tag-icons/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Angular PrimeNG Tag Icons

Last Updated : 19 Aug, 2022

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 see how to use the Tag Icons in Angular PrimeNG.

A tag component is used to make a tag in order to categorize the content. Tag Icons are used to add icons around the tags.

Angular PrimeNG Tag Icons 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.
  • styleClass: It defines the style class of the component. It is of string data type, the default value is null.
  • 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.

Syntax:

<p-tag 
    styleClass="...."
    severity="...." 
    value="...."
    icon="...">
</p-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:

ang.PNG

Project Structure

  • Run the below command:
ng serve --open

Example 1: Below is the example that illustrates the use of Angular PrimeNG Tag Icons using primary and success.

  • app.component.html
<h2 style="color: green">GeeksforGeeks</h2>
<h5>Angular PrimeNG Tag Icons</h5>
<p-tag styleClass="p-mr-2" 
value="Data Structure-Self Paced" 
icon="pi pi-code"
</p-tag>
<p-tag severity="success" 
value="Complete Interview Preparation" 
icon="pi pi-check"
</p-tag>
  • app.component.ts
import { Component } from "@angular/core";
@Component({
selector: "app-root",
templateUrl: "./app.component.html",
styleUrls: ["./app.component.scss"],
})
export class AppComponent {}
  • 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 {}

Output:

1.png

Example 2: Below is another example that illustrates the use of Angular PrimeNG Tag Icons using info, warning, and danger.

  • app.component.html
<h2 style="color: green">GeeksforGeeks</h2>
<h5>Angular PrimeNG Tag Icons</h5>
<p-tag styleClass="p-mr-2" 
severity="info" 
value="SQL-Self Paced" 
icon="pi pi-database"
</p-tag>
<p-tag styleClass="p-mr-2" 
severity="warning" 
value="Gate Preparation" 
icon="pi pi-pencil"
</p-tag>
<p-tag severity="danger" 
value="System Design" 
icon="pi pi-code"
</p-tag>
  • app.component.ts
import { Component } from "@angular/core";
@Component({
selector: "app-root",
templateUrl: "./app.component.html",
styleUrls: ["./app.component.scss"],
})
export class AppComponent {}
  • 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 {}

Output:

1.png

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

“This course was packed with amazing and well-organized content! The project-based approach of this course made it even better to understand concepts faster. Also the instructor in the live classes is really good and knowledgeable.”- Tejas | Deutsche Bank

With our revamped Full Stack Development Program: master Node.js and React that enables you to create dynamic web applications.

So get ready for salary hike only with our Full Stack Development Course.

Like Article
Suggest improvement
Share your thoughts in the comments

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK