Angular PrimeNG Chip Removable
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 Chips Removable in Angular PrimeNG.
The Chips component sets multiple values to enter for an input field. An icon can be used to close the chip that will be displayed when the removable property is set.
Syntax:
<p-chip label="..." image="..." [removable]="true"> </p-chip>
Angular PrimeNG Chip Removable properties:
- label: It is used to display the text inside the chip.
- removable: It is used to specify whether a removable icon should be shown or not. It is of boolean type. The default value is false.
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: It will look like the following:
- Run the below command to see the output:
ng serve --open
Example 1: Below is the example code that illustrates the use of the Angular PrimeNG Chip Removable.
app.component.html
< h2 style = "color: green" >w3wiki</ h2 > < h5 >Angular PrimeNG Chips Removable</ h5 > < div class = "p-d-flex p-ai-center" > < p-chip label = "DSA for Professionals" styleClass = "p-mr-3 geek" [removable]="true"> </ p-chip > < p-chip label = "DSA Self-Paced" styleClass = "p-mr-3 geek" [removable]="true"> </ p-chip > < p-chip label = "System Design" styleClass = "p-mr-3 geek" [removable]="true"> </ p-chip > < p-chip label = "C++ STL Self Paced" styleClass = "geek" [removable]="true"> </ p-chip > </ div > |
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 { ButtonModule } from "primeng/button" ; import { BadgeModule } from "primeng/badge" ; import { ChipModule } from "primeng/chip" ; @NgModule({ imports: [ BrowserModule, BrowserAnimationsModule, ChipModule, ButtonModule, BadgeModule ], declarations: [AppComponent], bootstrap: [AppComponent] }) export class AppModule {} |
Output:
Example 2: Below is another example code that illustrates Angular PrimeNG Chip Removable using the [removable]=”true” and styling properties.
app.component.html
< h2 style = "color: green" >w3wiki</ h2 > < h5 >Angular PrimeNG Chips Removable</ h5 > < div class = "p-d-flex p-ai-center" > < p-chip label = "DSA for Professionals" styleClass = "p-mr-3 geek" image = "https://media.w3wiki.net/wp-content/uploads/20220820113633/DSAforprofessionals-300x289.png" [removable]="true"> </ p-chip > < p-chip label = "DSA Self-Paced" styleClass = "p-mr-3 geek" image = "https://media.w3wiki.net/img-practice/banner/dsa-self-paced-course-overview-image.png?v=1660966260" [removable]="true"> </ p-chip > < p-chip label = "System Design" styleClass = "p-mr-3 geek" image = "https://media.w3wiki.net/img-practice/banner/system-design-live-course-overview-image.png?v=1660969521" [removable]="true"> </ p-chip > < p-chip label = "C++ STL Self Paced" styleClass = "geek" image = "https://media.w3wiki.net/img-practice/banner/cpp-stl-course-overview-image.png?v=1660972016" [removable]="true"> </ p-chip > </ div > |
app.component.ts
import { Component } from "@angular/core" ; @Component({ selector: "app-root" , templateUrl: "./app.component.html" , styleUrls: [ "./app.component.scss" ] }) export class AppComponent {} |
app.component.scss
:host ::ng-deep .p-chip.geek { background: var (--green-500); color: var (--primary-color-text); } |
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 { ButtonModule } from "primeng/button" ; import { BadgeModule } from "primeng/badge" ; import { ChipModule } from "primeng/chip" ; @NgModule({ imports: [ BrowserModule, BrowserAnimationsModule, ChipModule, ButtonModule, BadgeModule ], declarations: [AppComponent], bootstrap: [AppComponent] }) export class AppModule {} |
Output:
Reference: https://primefaces.org/primeng/chip
Contact Us