I encountered an issue resulting in the following error message:
core.es5.js:1020 ERROR Error: Uncaught (in promise): TypeError: date.getMonth is not a function
TypeError: date.getMonth is not a function
This error occurs whenever I attempt to implement two-way data binding with my JSON object received from the backend. Although the data type on the backend is Date, it does not display properly in the p-calendar input field. Seeking guidance for resolution.
{ "applicationId": 1, "entryDate": 1524665731000, "ongoingDescription": "<p>Ongoing entry should end in (5081421)</p>", "activeFlag": "Y" }
HTML
<div class="form-group">
<label>Date of the Ongoing Incident</label>
<br>
<p-calendar required [(ngModel)]="entry.entryDate" name="entryDate" #entryDate="ngModel" [showIcon]="true" [showTime]="true" dateFormat="mm/dd/y 'EST'" hourFormat="24"></p-calendar>
<div class="alert alert-danger" *ngIf="entryDate.touched && !entryDate.valid" >The date and time of the incident are required</div>
</div>
TS
entryDate: Date;
entry = {
}
constructor(private service: OngoingService, private route: ActivatedRoute,
private router: Router, private location: Location) {
this.id = this.route.snapshot.paramMap.get('id');
if (this.id) this.service.get(this.id).take(1).subscribe(service =>
this.entry = service);
}
ngOnInit() {
}
ngAfterContentInit() {
}
ngAfterViewInit() {
}
Your insights and advice are greatly appreciated.
I have attempted solutions like initializing entryDate = new Date(); and entryDate = new Date(this.entryDate);