ngx-bootstrap: Datepicker / Timepicker error. Typeerror Cannot read property 'getFullYear' when date assigned to null
I’m not 100% sure this is a ng2-bootstrap error but I think it is.
I have a Date object bound to datepicker. The date starts off as null. Then I assign it to new Date(). Everything is good up to this point. Then when I clear the date (assign the date to null) I get the following error:
EXCEPTION: Uncaught (in promise): TypeError: Cannot read property 'getFullYear' of null
TypeError: Cannot read property 'getFullYear' of null
at DatePickerInnerComponent.eval [as compareHandlerDay] (http://localhost:3000/node_modules/ng2-bootstrap/bundles/ng2-bootstrap.umd.js:8163:36)
at DatePickerInnerComponent.compare (http://localhost:3000/node_modules/ng2-bootstrap/bundles/ng2-bootstrap.umd.js:4519:25)
at DatePickerComponent.writeValue (http://localhost:3000/node_modules/ng2-bootstrap/bundles/ng2-bootstrap.umd.js:7946:30)
at eval (http://localhost:3000/node_modules/@angular/forms/bundles/forms.umd.js:1188:31)
at eval (http://localhost:3000/node_modules/@angular/forms/bundles/forms.umd.js:2217:69)
at Array.forEach (native)
at FormControl.setValue (http://localhost:3000/node_modules/@angular/forms/bundles/forms.umd.js:2217:32)
at eval (http://localhost:3000/node_modules/@angular/forms/bundles/forms.umd.js:3339:64)
at ZoneDelegate.invoke (http://localhost:3000/node_modules/zone.js/dist/zone.js:232:26)
at Object.onInvoke (http://localhost:3000/node_modules/@angular/core/bundles/core.umd.js:5976:41)
Here is my datepicker: (date1 is the object)
<datepicker [(ngModel)]="date1" (ngModelChange)="dateChanged()" [showWeeks]="false"></datepicker>
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 9
- Comments: 16 (4 by maintainers)
Think I just hit this issue too:
fixed in new datepicker (new style and pop up version) available in v1.9.0+ check this out: http://valor-software.com/ngx-bootstrap/#/datepicker#examples
I had the same issue with this one. Looking into it a bit, it seems it has been identified in code, but never fixed in
src/datepicker/datepicker.component.ts:And the culprit piece of code in
src/datepicker/datepicer-inner.component.tsis :As you can see, dates are checked to be undefined, but never null.
Then (in the daypicker case - mine) you compare 2 dates, where any one of these dates is acceptably null.
This is where the error originate. Trying to
getFullYear()of a null object.Setting date to
void 0, I can confirm works as well. What I ended up doing is setting the date toundefined. This is explicitly checked in code and hence does the same “job” as setting to null. Not a final solution, but definitely a workaround.Hope this helps people in the meantime.
It could be
Someone should take a look at this.
@Klinton90 , Can you tell me what exactly you do to resolve this error ? Where to assign this
value = void 0?This happens to me when
minDateormaxDateis specified but the model is undefined / null / whatever. Simple removing minDate and maxDate solved the problemI’m experiencing a similiar issue. My “from” date hat the “maxDate” set to “to” date. My “to” date has the “minDate” set to “from” date.
When “from” is null and “to” isnt, I’m getting “date.getTime is not a function” error and datepicker doesnt open. v2.0.2
Facing same issue. Assign
value = void 0;as temporary fix :\