1.0.0-rc.1 • Published 5 years ago

date-value-accessor v1.0.0-rc.1

Weekly downloads
-
License
MIT
Repository
github
Last release
5 years ago

DateValueAccessor for Angular

NPM version

Screenshot

A custom value accessor for Angular.
Now you can use <input type="date"> (provides real JavaScript date objects) directly with two-way data bindings (ngModel) as well as with reactive forms (formControlName/formControl).

Examples:

You have to explicitly opt-in by adding the attribute useValueAsDate to a date input control:

<input type="date" name="myBirthday" ngModel useValueAsDate>

OR

<input type="date" name="myBirthday" [(ngModel)]="myBirthday" useValueAsDate>

OR

<input type="date" formControlName="myBirthday" useValueAsDate>

Installation:

Download the package via NPM:

npm install --save angular-date-value-accessor

Then import the module via NgModule:

// app.module.ts

import { DateValueAccessorModule } from 'angular-date-value-accessor';

@NgModule({
  imports: [
    DateValueAccessorModule
  ]
})
export class AppModule { }

Now you can apply the "useValueAsDate" to your date input controls.

Demo

There is a demo at: http://johanneshoppe.github.io/angular-date-value-accessor/