Open In App

Angular PrimeNG Chips 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 Chips component in Angular PrimeNG.

Chips component: It is used to set multiple values to enter for an input field.



Properties:

Events:



 

Styling:

Creating Angular Application & module installation:

Project Structure: It will look like the following:

 

Example 1: This is the basic example that shows how to use the Chips component.




<div>
  <h2>GeeksforGeeks</h2>
  <h4>PrimeNG chips component</h4>
  <p-chips></p-chips>
</div>




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




import { NgModule } from "@angular/core";
import { BrowserModule } from "@angular/platform-browser";
import { FormsModule } from "@angular/forms";
import { HttpClientModule } from "@angular/common/http";
import { BrowserAnimationsModule } 
    from "@angular/platform-browser/animations";
  
import { AppComponent } from "./app.component";
import { ChipsModule } from "primeng/chips";
import { ButtonModule } from "primeng/button";
  
@NgModule({
  imports: [
    BrowserModule,
    BrowserAnimationsModule,
    ChipsModule,
    ButtonModule,
    FormsModule,
  ],
  declarations: [AppComponent],
  bootstrap: [AppComponent],
})
export class AppModule {}

Output:

Example 2: In this example, we have a template for the Chips component. 




<h5>PrimeNG Chips Component</h5>
<p-chips [(ngModel)]="geeks">
  <ng-template let-gfg pTemplate="gfg">
    {{gfg}}<i class="pi pi-user p-ml-2"></i>
  </ng-template>
</p-chips>




import { Component } from "@angular/core";
import { MenuItem } from "primeng/api";
  
@Component({
  selector: "my-app",
  templateUrl: "./app.component.html",
})
export class AppComponent {
  geeks: string[];
}




import { NgModule } from "@angular/core";
import { BrowserModule } from "@angular/platform-browser";
import { FormsModule } from "@angular/forms";
import { HttpClientModule } from "@angular/common/http";
import { BrowserAnimationsModule } 
    from "@angular/platform-browser/animations";
  
import { AppComponent } from "./app.component";
import { ChipsModule } from "primeng/chips";
import { ButtonModule } from "primeng/button";
  
@NgModule({
  imports: [
    BrowserModule,
    BrowserAnimationsModule,
    ChipsModule,
    ButtonModule,
    FormsModule,
  ],
  declarations: [AppComponent],
  bootstrap: [AppComponent],
})
export class AppModule {}

Output:

Reference: https://primeng.org/chips


Article Tags :