I am unable to assign value to `datetime-local element in a form.
Code from template:
Code from typescript file:
let dateTime : Date = new Date();
this.testForm = this.formBuilder.group({
'dateTime': new FormControl(dateTime),
});
Result:
What is the proper way to assign date & time to datetime-local using typescript
datetime-local
requires value in specific format (yyyy-mm-ddThh:mm)
You can try the following,
const dateTime = new Date();
this.testForm = this.formBuilder.group({
dateTime: new FormControl(dateTime.toISOString().substring(0, 16)),
});