src/lib/dl-date-time-input/dl-date-time-input.directive.ts
This directive allows the user to enter dates, using the keyboard, into an input box and angular will then store a date value in the model.
The input format(s), display format, and model format are independent and fully customizable.
ControlValueAccessor
Validator
Providers |
{ provide: NG_VALUE_ACCESSOR, useExisting: DlDateTimeInputDirective, multi: true }
{ provide: NG_VALIDATORS, useExisting: DlDateTimeInputDirective, multi: true }
|
Selector | input[dlDateTimeInput] |
Methods |
Inputs |
Outputs |
HostListeners |
Accessors |
constructor(_renderer: Renderer2, _elementRef: ElementRef, _dateAdapter: DlDateAdapter<D>, _displayFormat: string, _inputFormats: string[])
|
||||||||||||||||||||||||
Constructs a new instance of this directive.
reference to the renderer.
reference to this element.
date adapter for the date type in the model.
from
Parameters :
|
dlDateTimeInputFilter | |
Type : boolean
|
|
Set a function used to determine whether or not the |
dateChange | |
Type : EventEmitter
|
|
Emits when a |
blur |
Format the input text using DL_DATE_TIME_DISPLAY_FORMAT and mark the control as touched. |
change |
Emit a |
input | ||||||
Arguments : '$event.target.value'
|
||||||
Parse the user input into a possibly valid date. The model value is not set if the input is NOT one of the DL_DATE_TIME_INPUT_FORMATS. Value of the input control.
Parameters :
|
_onBlur |
_onBlur()
|
Decorators :
@HostListener('blur')
|
Format the input text using DL_DATE_TIME_DISPLAY_FORMAT and mark the control as touched.
Returns :
void
|
_onChange |
_onChange()
|
Decorators :
@HostListener('change')
|
Emit a
Returns :
void
|
_onInput | ||||||||
_onInput(value: string | null | undefined)
|
||||||||
Decorators :
@HostListener('input', ['$event.target.value'])
|
||||||||
Parse the user input into a possibly valid date. The model value is not set if the input is NOT one of the DL_DATE_TIME_INPUT_FORMATS. Value of the input control.
Parameters :
Returns :
void
|
dlDateTimeInputFilter | ||||||||
setdlDateTimeInputFilter(inputFilterFunction: (value: D | null) => void)
|
||||||||
Set a function used to determine whether or not the
Parameters :
Returns :
void
|
value | ||||||||
getvalue()
|
||||||||
Returns
Returns :
D
|
||||||||
setvalue(newValue: D | null | undefined)
|
||||||||
Set the value of the date/time input to a value of
Parameters :
Returns :
void
|
This directive provides all of the user facing functionality to input a date and/or time using the keyboard. |
Import the module corresponding to the desired data type of the date in the model.
DlDateTimePickerDateModule
DlDateTimePickerMomentModule
DlDateTimePickerNumberModule
DlDateTimePickerStringModule
A DateAdapter
is used to adapt the data type in the model to the number
data type
used internally by the date/time picker.
If you need a different data type than what is currently supported, you can extend
DlDateAdapter<D>
to provide the data type you need then override the DlDateAdapter
provider in app.module.ts
to use your new class.
providers: [{provide: DlDateAdapter, useClass: MyCustomDateAdapter}],
The display format is defined in the DL_DATE_TIME_DISPLAY_FORMAT
token and is injected into this component
to control the display format.
DL_DATE_TIME_DISPLAY_FORMAT
defaults to moment
's lll
long date format.
Override DL_DATE_TIME_DISPLAY_FORMAT
if you do not like the default format.
{provide: DL_DATE_TIME_DISPLAY_FORMAT, useValue: '<what ever format you want goes here>'}
This directive supports multiple input formats, as defined in the DL_DATE_TIME_INPUT_FORMATS
token.
When the user inputs a string value into a text box, this directive attempts to parse the input
using one of the specified formats, in the order the format occur in the array.
Once one of the formats is able to parse the user input, the date is set in the model.
Nota bene For convenience DL_DATE_TIME_INPUT_FORMATS
defaults to support multiple formats,
which can dramatically slow down parsing performance. It can also result in successfully parsing
a date using a format that is not appropriate for your use case.
Consider overriding the DL_DATE_TIME_INPUT_FORMATS
token to only include the specific formats required by your project.
{provide: DL_DATE_TIME_INPUT_FORMATS, useValue: ['<input format zero>', ..., '<input format N>']}
See moment's parsing multiple formats page for more information on how these date formats are used.