I am new to angular and material 2, I am using material date picker in my form to display and select the date. I am able to select the date and bind to ngModel. But when I try to bind my response to ngModel showing nothing. I have converted my string date to date and then binding to ngModel. Below is the code, Please help me where i am missing.
<mat-form-field>
<input matInput id="dateOfBirth" name="dateOfBirth" [matDatepicker]="dateOfBirth"
class="form-control" [(ngModel)]="customer.dateOfBirth"
placeholder="Date of birth" required>
<mat-datepicker-toggle matSuffix [for]="dateOfBirth"></mat-datepicker-toggle>
<mat-datepicker #dateOfBirth></mat-datepicker>
<mat-error>Date of birth is required</mat-error>
</mat-form-field>
my ts file getting the response from json
customer: CustomerModel = new CustomerModel();
this.customerService.getResponse().subscribe(resp => {
this.customer= resp;
console.log('Date:'+this.customer.dateOfBirth);// able to print
});
Class CustomerModel {
dateOfBirth: Date;
//other customer details
}
Here I have created sample https://stackblitz.com/edit/angular-pvqugs