javascript - Error: Datepicker: value not recognized as a date object by DateAdapter -
from yesterday i'm struggling problem angular material 2 datepicker, before last npm install
working , get:
error error: datepicker: value not recognized date object dateadapter. holidayrequestcomponent.html:21
21st line <input
starts
<md-input-container [formgroup]="daterangeform"> <input mdinput name="date_from" [mddatepicker]="from" placeholder="start date" formcontrolname="holidaydatacontrol" [ngmodel]="date_from" > <md-datepicker-toggle mdsuffix [for]="from"></md-datepicker-toggle> </md-input-container> <md-datepicker #from></md-datepicker>
my component.ts:
import {component, oninit, inject } '@angular/core'; import {md_dialog_data, mddialog } '@angular/material'; import {formbuilder, formcontrol, formgroup, ngform, validators} '@angular/forms'; import {observable} 'rxjs/observable'; @component({ selector: 'app-holiday-request', templateurl: './holiday-request.component.html', styleurls: ['./holiday-request.component.css'] }) export class holidayrequestcomponent implements oninit { public date_from = new date(); constructor(@inject(md_dialog_data) public data: any, private fb: formbuilder, ) { this.daterangeform = new formgroup({ holidaydatacontrol: new formcontrol('', validators.required) }); } }
according https://github.com/angular/material2/issues/6265
an empty string not acceptable value , raising following error:
datepicker: value not recognized date object dateadapter.
so solutions change
this.daterangeform = new formgroup({ holidaydatacontrol: new formcontrol('', validators.required) });
to
this.daterangeform = new formgroup({ holidaydatacontrol: new formcontrol(null, validators.required) });
Comments
Post a Comment