Reputation: 223
I have a date which is fetched from the backed as 30-10-2019 (DD-MM-YYYY)
format. I am trying to get this date to be displayed in angular material datepicker but its not displaying the date.
I tried moment and used moment (this.myDate).format('YYYY-MM-DD')
.toString(); What am I missing? Any other method (without using moment) is also fine.
Upvotes: 1
Views: 1489
Reputation: 2027
you need pass the date format to moment like below and assign that to your formControl or ngModel. Assuming your ngModel is date then code will be
this.date = moment(this.myDate, 'DD-MM-YYYY');
Here is the working example : https://stackblitz.com/edit/angular-w9szcc.
Hope this helps.
Upvotes: 0