A reusable Angular duration-picker component that works with ISO_8601 durations.
Requires Bootstrap, css only (no Bootstrap JS or jQuery needed).
- Run:
npm install --save ngx-duration-picker
- Then in your
app.module.ts
addDurationPickerModule
between yourimports
:
@NgModule({
declarations: [...],
imports: [
DurationPickerModule,
...
],
providers: [...],
bootstrap: [AppComponent]
})
export class AppModule { }
-
On one terminal tab run
ng build ngx-duration-picker --watch
. This will build the library sources (projects/ngx-duration-picker/*
) and watch for changes. -
On another terminal tab run
ng serve
to serve the demo app (src/*
) and play with it.
<ngx-duration-picker [(value)]="myDuration"></ngx-duration-picker>
where myDuration will be the variable where the output is stored, you can also pass an initial value.
if you need to perform some operations each time the bound variable changes, you can use (valueChange)
:
<ngx-duration-picker [(value)]="myDuration" (valueChange)="doSomeStuff()">
you can pass specify some options by binding [options]
to your configuration object:
<ngx-duration-picker [(value)]="myDuration" [options]="{ showWeeks: false }">
String or Null, default 'PT0S'
.
Value to be used when the duration is 0. Since the specification says that 'PT0S'
or 'P0D'
are both valid, you are allowed to change this value. You can also pass just null
.
Boolean, default false
. Sets up the option for negative and positive durations.
Boolean, default true
. Shows the up and down buttons.
Boolean, default true
. Shows a preview of the value.
String, default ISO
.
You can optionally specify a date format using:
{{Y}}
for years{{M}}
for months{{W}}
for weeks{{D}}
for days{{h}}
for hours{{m}}
for minutes{{s}}
for seconds
Example string: {{h}} hours : {{m}} minutes : {{s}} seconds
String, default ISO
.
You can optionally specify:
timestamp
for duration in millisecondsseconds
for duration in seconds- custom string as described in
previewFormat
option
Chosen value will be emitted by customOutput
.
Boolean, default true
. Shows the letters on top (Y, M, W, D, H, M, S)
Object, accepting labels that should be shown above the fields instead of default letters (showLetters
has to be set to true).
Available fields (with default labels):
- years (
Y
) - months (
M
) - weeks (
W
) - days (
D
) - hours (
H
) - minutes (
M
) - seconds (
S
)
Example object which is overwriting weeks
and hours
properties:
{
weeks: 'tyg',
hours: 'godz'
}
Boolean, default true
. Shows the years, when hidden it will be always considered as 0.
Boolean, default true
. Shows the months, when hidden it will be always considered as 0.
Boolean, default true
. Shows the weeks, when hidden it will be always considered as 0.
Boolean, default true
. Shows the days, when hidden it will be always considered as 0.
Boolean, default true
. Shows the hours, when hidden it will be always considered as 0.
Boolean, default true
. Shows the minutes, when hidden it will be always considered as 0.
Boolean, default true
. Shows the seconds, when hidden it will be always considered as 0.