What it is
PrimeNG is a comprehensive UI component library for Angular, offering a wide range of rich and responsive components including forms, data tables, charts, menus, and more, following modern design patterns.
PrimeNG provides Angular modules for each component. You can import and use them in your templates, with support for two-way binding, events, and customization.
Installation
npm install primeng primeiconsGetting started
The smallest useful thing you can do with it, and what each part means.
import { ButtonModule } from 'primeng/button';
@NgModule({ imports: [ButtonModule] })
export class AppModule {}
<p-button label="Click Me" icon="pi pi-check"></p-button>import { InputTextModule } from 'primeng/inputtext';
<input type="text" pInputText placeholder="Enter text" />Advanced usage
Where the library earns its place over a simpler alternative.
import { TableModule } from 'primeng/table';
<p-table [value]="cars">
<ng-template pTemplate="header">
<tr>
<th>Vin</th>
<th>Year</th>
<th>Brand</th>
<th>Color</th>
</tr>
</ng-template>
<ng-template pTemplate="body" let-car>
<tr>
<td>{{car.vin}}</td>
<td>{{car.year}}</td>
<td>{{car.brand}}</td>
<td>{{car.color}}</td>
</tr>
</ng-template>
</p-table><p-dialog header="Title" [(visible)]="display">
<p>Content goes here.</p>
</p-dialog>
<p-button label="Show Dialog" icon="pi pi-external-link" (onClick)="display=true"></p-button>import { DropdownModule } from 'primeng/dropdown';
<p-dropdown [options]="cities" [(ngModel)]="selectedCity" placeholder="Select a City"></p-dropdown>Errors and fixes
The failures you are most likely to hit, and what actually resolves them.
- Styles not applied
- Ensure you imported PrimeNG theme CSS and PrimeIcons CSS in angular.json.
- Two-way binding not working
- Ensure [(ngModel)] is used and FormsModule is imported in your module.
- Components not rendered
- Verify that the corresponding PrimeNG module is imported in your NgModule.
Best practices
- Import only the PrimeNG modules you need to reduce bundle size.
- Use Angular reactive forms for form components with two-way binding.
- Apply themes from PrimeNG for consistent styling.
- Combine PrimeNG components with Angular services for dynamic data handling.
- Check component documentation for available events and properties for better integration.
Background
Why it exists, and what it was reacting to.
PrimeNG was developed by PrimeTek Informatics to provide Angular developers with a robust and feature-rich set of UI components. It emphasizes accessibility, responsiveness, and ease of use, making it popular in both enterprise and community projects.
