The first solution provided is great, as it solves your solution with Vanilla JavaScript!
However, I have two other alternative solutions.
1) This makes use of Angular's built-in DatePipe. You can even pass in a variety of DateTime formats.
import { DatePipe } from '@angular/common';
.
.
export class SampleComponent implements OnInit {
constructor(private datePipe: DatePipe) {
this.addItems.achievement_date = datePipe.transform('2019-04-13T00:00:00', 'yyyy-MM-dd');
// console.log(this.date)
}
}
Do remember to import DatePipe to your providers in your module that is using it.
import { DatePipe } from '@angular/common';
.
.
@NgModule({
.
.,
providers: [
DatePipe
]
})
The above should display the dates on the input field.
I have made a demo using the above solution
2) formatDate. Do take note that this may not work on the earlier versions of Angular. So far, I have only tried and tested it on Angular 7.
import {formatDate } from '@angular/common';
.
.
export class AppComponent {
date = undefined;
constructor() {
this.date = formatDate('2019-04-13T00:00:00', 'yyyy-MM-dd', 'en-US');
}
}
here is another demo for you.