0

I am using Angular2 material-design datepicker but when I select any date is throws an error "The specified value does not conform to required standard
"yyyy-MM-dd". I have tried to amend the locale but to no avail.

HTML

  <div>

 <md-input-container>
  <input mdInput [mdDatepicker]="picker" placeholder="Date" 
  formControlName="dateOfPurchase" ngDefaultControl 
  [formControl]="dtPurchase" [(ngModel)]="dateOfPurchase" required 
  type="date" name="dateOfPurchase" id="dateOfPurchase">
  <button mdSuffix [mdDatepickerToggle]="picker"></button>
 </md-input-container>
 <md-datepicker #picker></md-datepicker>

  </div>

Typescript

import { DateAdapter } from '@angular/material';

constructor(private dateAdapter: DateAdapter<Date>)
{
    this.dateAdapter.setLocale('gb');
    this.dtPurchase= new FormControl();
}

Any help appreciated.

@Nehal

Your suggestion on the example works but error still persists - see pic below

DateTimepicker Error

Ram
  • 527
  • 1
  • 10
  • 26
  • Is this the only code you have inside the class? where is the part where you initialize the date picker values – Vega Aug 15 '17 at 15:55
  • You need a custom `NativeDateAdapter` to parse the dd/mm/yyyy format. Check this [answer](https://stackoverflow.com/a/45525364/5556177). – Nehal Aug 15 '17 at 17:30
  • @Nehal Thanks this works fine but still getting warning errors - have attached pic to my original post... – Ram Aug 16 '17 at 08:26

0 Answers0