NgxCrontabBuilder is an Angular/PrimeNG control that allows users to visually edit a CRONTAB string in the Qaurtz format.
This project is an Angular port of my original CrontabBuilder for WPF.
A live demo is available here
- Upgraded to work with Angular 17 / PrimeNG 17
- See changelog
This component was developed using PrimeNG. Your project needs to include the primeng
, primeicons
and primeflex
packages for the component to work properly.
The version number of the library matches the required version of Angular
/ PrimeNG
, so install the appropriate version (for example: if using Angular 16
, install ngx-crontab-builder ^16.0.0
).
The package is available on the NPM registry. Install it with:
npm install ngx-crontab-builder
To use the control, first import the NgxCrontabBuilderModule
module in your Angular app:
import { ComponentStyle } from "ngx-crontab-builder";
The control supports both ngModel data binding and reactive forms. Depending on which one you're using, use the following instructions:
Like a normal input element, you can bind a string
property to the component via ngModel
syntax:
<ngx-crontab-builder [(ngModel)]="currentCrontab"></ngx-crontab-builder>
When the user updates the configuration the new CRONTAB string will be assigned to the bound variable. Vice-versa, you can also assign a CRONTAB string to the bound property and the component will parse it and update accordingly, selecting the active mode and parameters. Note that this is only guaranteed to work with CRONTAB strings generated by the component, any unrecognized string will set the component in "custom" mode.
You can also use ngModelChange
to be notified when the CRONTAB string changes:
(ngModelChange)="crontabUpdated($event)"
the $event
will be a string containing the new CRONTAB value.
If you're using reactive forms, simply specify the form control to use:
<ngx-crontab-builder [formControl]="crontabControl"
You can use the usual reactive form control facilities (valueChanges
and setValue
) to listen for changes and manually change the value in code respectively.
The ngx-crontab-builder
component exposes the following properties that can be used for further customization:
locale
- sets the component language, must be a ISO 639-1 2-digits language code. If not set "en" (english) is the defaultcomponentStyle
- the visual style of the component, can be one of the following values of theComponentStyle
enum:FIELDSETS
(default) - component styled as a panel with a series of field sets, one for each sectionPLAIN
- component styled as a plain panel with a series of dividers separating each sectionTABBED
- component styled as a tabbed view, with one tab for each section
showSecondsMode
- shows or hides the "every X seconds" sectionshowMinutesMode
- shows or hides the "every X minutes" sectionshowHoursMode
- shows or hides the "every X hours" sectionshowDayMode
- shows or hides the "every day" sectionshowWeekMode
- shows or hides the "every week" sectionshowNthDayOfWeekMode
- shows or hides the "every nth week day" sectionshowMonthMode
- shows or hides the "every month" sectionshowLastDayOfMonthMode
- shows or hides the "last day of the month" sectionshowCustomExpressionMode
- shows or hides the "custom Cron expression" section
Library can be built via angular CLI:
ng build ngx-crontab-builder
A demo web app that showcases the control is provided in the projects/crontab-builder-demo
folder.
To launch it, first build the library, then issue the following command:
ng serve crontab-builder-demo
Localization contributions are welcome! At the moment the available languages are:
english
(by: me)italian
(by: me)
If you want to contribute an additional translation:
- Make a copy of
projects/ngx-crontab-builder/src/lang/en.ts
and put it in the same folder, naming itXX.ts
, whereXX
is the ISO 639-1 2-digits code of the language you want to contribute. - Translate all the strings in the file
- Update
projects/ngx-crontab-builder/src/lib/services/translate.service.ts
to include the new language:- Import the
XX.ts
file - Add the language object to the
locales
array at the start of the class
- Import the
- If every thing works correctly, make a pull request with these changes and I'll merge it!