Image Image Image Image Image
Scroll to Top

To Top

2016 Oktober

Angular 2: How to use date input controls with Angular Forms

On 12, Okt 2016 | Keine Kommentare | inAngular2 | vonJohannes Hoppe

screenshot

NPM version

The problem

Working with forms is pretty easy in Angular 2. You just need to decide between Template-Driven and Reactive Forms and you are ready to start with some bindings and validation. The following code shows a two-way data binding with ngModel against a property of type string:

<input type="text" name="name" [(ngModel)]="myName">

But there is one problem to tackle: models of type Date!
You might wonder, because HTML5 date input controls are not working as expected: