In my Angular App , I am Showing data from API to component in input fields .
All fields are getting populated but not Input element with type Date
Below is html markup
<input [(ngModel)]="CustomerVM.customer.CustomerDob" type="date" name="MemberDateOfBirth" class="form-control"
(blur)="Calculate_Age(CustomerVM.customer.CustomerDob)">
In console it say
The specified value "2018-09-21T00:00:00" does not conform to the required format, "yyyy-MM-dd".
I made a common function to format date in a service as
FormatDate(iDate: Date) {
var inputDate:Date= new Date(iDate);
var formattedDate = new Date(inputDate.getUTCDate(), (inputDate.getUTCMonth() + 1), inputDate.getUTCFullYear());
return formattedDate;
}
and
this.CustomerVM.customer.CustomerDob = this.Helper.FormatDate(this.CustomerVM.customer.CustomerDob);
but it does not show value in date field
inside interpolation block we can format value by using pipes
{{DOB | date:'mediumDate'}}
Can we do this with ngModel too? cause I don't want a method to format it.
How can I achieve this ?