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)

Image of Docusign

Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay