Angular PrimeNG Form Chips Templates
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. This article will show us how to use Angular PrimeNG Form Chips Templates Component.
The Chips component is used to set multiple values to enter for an input field. Angular PrimeNG Form Chips Templates are used to put some content on some pre-structured containers. Form Chips templates are discussed below:
- chip: This is used to create template for the Form Chips Template
Syntax:
<p-chips> <ng-template let-item pTemplate="chip"> ... </ng-template> </p-chips>
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:
Example 1: In this example, we will learn about Angular PrimeNG Form Chips Templates Component.
app.component.html
HTML
< div style = "width: 50%" > < h1 style = "color:green" > GeeksforGeeks </ h1 > < h2 > Angular PrimeNG Form Chips Templates Component </ h2 > < div class = "p-fluid" > < p-chips > < ng-template let-item pTemplate = "chip" > {{item}} </ ng-template > </ p-chips > </ div > </ div > |
app.component.ts
Javascript
import { Component } from '@angular/core' ; import { MenuItem } from 'primeng/api' ; @Component({ selector: 'app-root' , templateUrl: './app.component.html' }) export class AppComponent { } |
app.module.ts
Javascript
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 will add an icon in the chip template.
app.component.html
Javascript
<div style= "width:50%" > <h1 style= "color:green" > GeeksforGeeks </h1> <h2> Angular PrimeNG Form Chips Templates Component </h2> <div class= "p-fluid" > <p-chips> <ng-template let-item pTemplate= "chip" > {{item}} <i class= "pi pi-user p-ml-2" ></i> </ng-template> </p-chips> </div> </div> |
app.component.ts
Javascript
import { Component } from '@angular/core' ; import { MenuItem } from 'primeng/api' ; @Component({ selector: 'app-root' , templateUrl: './app.component.html' }) export class AppComponent { } |
app.module.ts
Javascript
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://primefaces.org/primeng/chips
Please Login to comment...