DEV Community

CodetoLive blog
CodetoLive blog

Posted on • Originally published at codetolive.in on

PrimeNG setup in Angular 19

1. What is PrimeNG?

PrimeNG is an open-source library with prebuilt and customizable UI components that speed up the development process for Angular. It comes under the free-to-use MIT license.

2. Find your Angular version

Run the command ‘ng v’ in your terminal to find the Angular version.
Fig 1: Angular version

Fig 1: Angular version

3. Install PrimeNG

3.1. Install PrimeNG and PrimeNG theme

Run the command ‘npm install primeng @primeng/themes’ in your terminal to install PrimeNG and its themes.

3.2. Possible encountering installation error

You may face an installation error while installing the PrimeNG npm packages.

Fig 2: PrimeNG installation error

3.4. Solution to installation failure

Fix the upstream dependency conflict or retry this command with –force

Retry the same command with ‘–force’,

‘npm install primeng @primeng/themes –save –force’ to install the PrimeNG packages.

4. Verify your installation

Verify the installation of PrimeNG by checking the package.json file.

Fig 3: PrimeNG verify installation

5. Add reference to PrimeNG

5.1. Add reference to PrimeNG (app.config.ts approach)

Add a reference to PrimeNG animation, ProvidePrimeNG, and the theme (‘Aura’) in your app.config.ts to use the PrimeNG UI components across your Angular project. You may not have needed to manually add the CSS references in the angular.json or global styles.css file because it will be taken care of by the PrimeNG themes package in the newer PrimeNG version 19.

app.config.ts,

import { ApplicationConfig } from '@angular/core';
import { provideAnimationsAsync } from '@angular/platform-browser/animations/async';
import { providePrimeNG } from 'primeng/config';
import Aura from '@primeng/themes/aura';

export const appConfig: ApplicationConfig = {
    providers: [
        provideAnimationsAsync(),
        providePrimeNG({
            theme: {
                preset: Aura
            }
        })
    ]
};

ButtonDemo.Component.ts,

import { Component } from '@angular/core';
import { ButtonModule } from 'primeng/button';

@Component({
    selector: 'button-demo',
    templateUrl: './button-demo.html',
    standalone: true,
    imports: [ButtonModule]
})
export class ButtonDemo {}

ButtonDemo.Component.html
<div class="card flex justify-center">
    <p-button label="Check" />
</div>

Enter fullscreen mode Exit fullscreen mode

5.2 Add reference to PrimeNG (app.module.ts approach)

app.module.ts,

import { provideAnimationsAsync } from '@angular/platform-browser/animations/async';
import { providePrimeNG } from 'primeng/config';
import Aura from '@primeng/themes/aura';

import { ButtonModule } from 'primeng/button';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    FormsModule,
    HttpClientModule,
    ButtonModule
  ],
  providers: [provideAnimationsAsync(),
    providePrimeNG({
        theme: {
            preset: Aura
        }
    })],
  bootstrap: [AppComponent]
})
export class AppModule { }

ButtonDemo.Component.html
<div class="card flex justify-center">
    <p-button label="Check" />
</div>

Enter fullscreen mode Exit fullscreen mode

5.3 Output (Button)

Fig 4: Output (Button)

Postmark Image

"Please fix this..."

Focus on creating stellar experiences without email headaches. Postmark's reliable API and detailed analytics make your transactional emails as polished as your product.

Start free

Top comments (0)

Image of Datadog

Get the real story behind DevSecOps

Explore data from thousands of apps to uncover how container image size, deployment frequency, and runtime context affect real-world security. Discover seven key insights that can help you build and ship more secure software.

Read the Report

👋 Kindness is contagious

Explore this insightful post in the vibrant DEV Community. Developers from all walks of life are invited to contribute and elevate our shared know-how.

A simple "thank you" could lift spirits—leave your kudos in the comments!

On DEV, passing on wisdom paves our way and unites us. Enjoyed this piece? A brief note of thanks to the writer goes a long way.

Okay