// Tutorial //

How To Use PrimeNG Components in Angular

Published on October 6, 2017 · Updated on August 10, 2021
Default avatar
By Alligator.io
Developer and author at DigitalOcean.
How To Use PrimeNG Components in Angular


PrimeNG from PrimeFaces is an alternative UI component library. It offers a selection of pre-built themes and UI components for data presentation, form inputs, menus, charts, overlays, and more.

In this article, you will set up PrimeNG in an Angular 4+ project and explore some of the main components.


If you would like to follow along with this article, you will need:

This tutorial was verified with Node v16.6.1, npm v7.20.3, @angular/core v12.2.0, and primeng v12.0.1, and primeicons v4.1.0.

Setting Up the Project

You can use @angular/cli to create a new Angular Project.

In your terminal window, use the following command:

  1. ng new AngularPrimeNGExample --style=css --routing=false --skip-tests

This will configure a new Angular project with styles set to “CSS” (as opposed to “Sass”, Less", or “Stylus”), no routing, and skipping tests.

Navigate to the newly created project directory:

  1. cd AngularPrimeNGExample

To get started, install the required packages: primeng and primeicons into your project:

  1. npm install primeng@12.0.1 primeicons@4.1.0

At this point, you have a new Angular project with primeng and primeicons.

Adding PrimeNG Styles

Next, add the required CSS files as part of the styles loaded by the Angular CLI:

angular.json (partial)
"styles": [

**Note: You will need to restart your local server after adding to the angular.json configuration file.

Here we’re using the saga-blue theme, but you can choose between available themes like nova, rhea or fluent-light.

Importing PrimeNG Components

Now let’s setup our app module to include the UI components we want:

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';

import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { FormsModule } from '@angular/forms';

import { AccordionModule } from 'primeng/accordion';
import { PanelModule } from 'primeng/panel';
import { ButtonModule } from 'primeng/button';
import { RadioButtonModule } from 'primeng/radioButton';

import { AppComponent } from './app.component';

  declarations: [
  imports: [
  providers: [],
  bootstrap: [AppComponent]
export class AppModule { }

Notice how we also imported Angular’s BrowserAnimationsModule and FormsModule. The animation module is required by PrimeNG’s components and the form module will be needed to use form input components like the radio button component.

At this point, you have a new Angular project with support for AccordionModule, PanelModule, ButtonModule, and RadioButtonModule.

Building an App with PrimeNG Components

Here’s an example that uses PrimeNG’s accordion, panel, radio button, and button components.

Add pizzaSelection:

import { Component } from '@angular/core';

  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
export class AppComponent {
  pizzaSelection = ''

Then add p-accordion, p-accordionTab, p-radioButton, p-panel, and pButton:

  <p-accordionTab header="Salads">
  <p-accordionTab header="Pasta">
  <p-accordionTab header="Pizza" [selected]="true">
        label="Double cheese"



<p-panel header="Extras" *ngIf="pizzaSelection && pizzaSelection.length">
  Would you like extra cheese on your pizza?
  <button pButton type="button" label="Ok, yeah!"></button>

Notice how the components use the p- prefix.

Save the changes to your file and serve the application.

Screenshot of PrimeNG accordions, panels, radio buttons, and buttons.

If you select a pizza, the Extras panel will appear and prompt users to add extra cheese.


In this article, you set up PrimeNG in an Angular 4+ project and explore some of the main components.

Continue your learning by consulting the official documentation for a showcase and documentation of all the available components.

Explore alternative UI component libraries with Angular Material 2.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in our Questions & Answers section, find tutorials and tools that will help you grow as a developer and scale your project or business, and subscribe to topics of interest.

Sign up
About the authors
Default avatar
Developer and author at DigitalOcean.

Still looking for an answer?

Was this helpful?

Why to use *ngIf in “pizzaSelection && pizzaSelection.length”?