我想从 JSON 输出 mat-datepicker 的输入字段中的日期。当我运行输出时,我总是得到当前年份。我正在使用 ReactiveForms。我究竟做错了什么?
我的代码:
// JSON
{
"success": true,
"mandant": {
"mandantId": 2,
"firm": "Test GmbH",
"street": "Test-Street",
"number": "2",
"zip": "5xxxx",
"city": "Exxxxxxxx",
"country": "Germany",
"financial_year_start": "Jan. 1, 2020" // This is to be output in the input
}
}
// TS
public getFiscalYearStart: string;
ngOnInit() {
// To initialize forms
this.initForm();
// To initialize loadFinancialYearStart
this.loadFinancialYearStart();
}
// Creation of the settingsContentForm
private initForm() {
// General
this.settingsContentForm = this.formBuilder.group({
financial_year_start: new FormControl(moment(this.getFiscalYearStart), Validators.required),
});
}
/**
* Fill the datePicker with data
*/
loadFinancialYearStart() {
this.userAreaService.getCurrentMandantData().subscribe(resp => {
this.getFiscalYearStart = resp.mandant.financial_year_start;
console.log(this.getFiscalYearStart); // Correct year is displayed in the console
});
}