Primitives
A date picker is a component that allows users to select a date from a calendar and navigate through months and years.
Import the DatePicker primitives from ng-primitives/date-picker.
import {
NgpDatePicker,
NgpDateRangePicker,
NgpDatePickerLabel,
NgpDatePickerNextMonth,
NgpDatePickerPreviousMonth,
NgpDatePickerGrid,
NgpDatePickerCell,
NgpDatePickerRowRender,
NgpDatePickerCellRender,
NgpDatePickerDateButton,
} from 'ng-primitives/date-picker';
Assemble the date-picker directives in your template.
<div ngpDatePicker>
<div>
<button ngpDatePickerPreviousMonth>...</button>
<h2 ngpDatePickerLabel>...</h2>
<button ngpDatePickerNextMonth>...</button>
</div>
<table ngpDatePickerGrid>
<thead>
<tr>
<th scope="col" abbr="Sunday">S</th>
...
</tr>
</thead>
<tbody>
<tr *ngpDatePickerRowRender>
<td *ngpDatePickerCellRender="let date" ngpDatePickerCell>
<button ngpDatePickerDateButton>...</button>
</td>
</tr>
</tbody>
</table>
</div>
Create a reusable component that uses the date picker directives.
Generate a reusable date-picker component using the Angular CLI.
ng g ng-primitives:primitive date-picker
path: The path at which to create the component file.prefix: The prefix to apply to the generated component selector.component-suffix: The suffix to apply to the generated component class name.file-suffix: The suffix to apply to the generated component file name. Defaults to component.example-styles: Whether to include example styles in the generated component file. Defaults to true.Here are some additional examples of how to use the Date Picker primitives.
The date range picker allows users to select a range of dates by selecting the start and end dates.
By default, the date picker uses the native JavaScript Date object, however the date picker is designed to work with any date library. To use a date library, such as Luxon, you need to specify the appropriate date adapter. The date adapter is an abstraction layer that allows components to use date objects from any date library, ensuring compatibility and easy integration. To learn more about the date adapter, see the Date Adapter documentation.
The following directives are available to import from the ng-primitives/date-picker package:
A structural directive that renders a cell in the date picker grid.
*ngpDatePickerCellRenderngpDatePickerCellRenderThe following context fields are available on the ngpDatePickerCellRender directive:
Adheres to the WAI-ARIA design pattern.
You can configure the default options for all NgpDatePicker and NgpDateRangePicker calendars in your application by using the provideDatePickerConfig function in a providers array.
import { provideDatePickerConfig } from 'ng-primitives/date-picker';
bootstrapApplication(AppComponent, {
providers: [
provideDatePickerConfig({
firstDayOfWeek: 1, // Monday
}),
],
});
Copyright © 2026 Angular Primitives
This site is powered by Netlify