angular2-datetimepicker icon indicating copy to clipboard operation
angular2-datetimepicker copied to clipboard

DatePicker.html:60 ERROR TypeError: Cannot read property 'getMonth' of undefined(…)

Open vignesh2694 opened this issue 7 years ago • 12 comments

please help.

I followed these steps

https://www.npmjs.com/package/angular2-datetimepicker

vignesh2694 avatar Jan 19 '18 07:01 vignesh2694

Is it within a form tag ? If so, you need to specify the name attribute.

Puex avatar Jan 19 '18 15:01 Puex

Same issue with me as well. Yes it was under form and I do have specified name but still same error:

ERROR TypeError: Cannot read property 'getMonth' of undefined
    at Object.eval [as updateDirectives] (DatePicker.html:60)
    at Object.debugUpdateDirectives [as updateDirectives] (core.es5.js:13056)
    at checkAndUpdateView (core.es5.js:12236)
    at callViewAction (core.es5.js:12601)
    at execEmbeddedViewsAction (core.es5.js:12559)
    at checkAndUpdateView (core.es5.js:12237)
    at callViewAction (core.es5.js:12601)
    at execComponentViewsAction (core.es5.js:12533)
    at checkAndUpdateView (core.es5.js:12242)
    at callViewAction (core.es5.js:12601)
    at execComponentViewsAction (core.es5.js:12533)
    at checkAndUpdateView (core.es5.js:12242)
    at callViewAction (core.es5.js:12601)
    at execEmbeddedViewsAction (core.es5.js:12559)
    at checkAndUpdateView (core.es5.js:12237)

If I move it outside form, it works fine - however, name property is still required.

rakesh410 avatar Jan 31 '18 09:01 rakesh410

We ran into this same issue. For some reason, when you use this component within a form, it tries to evaluate that bit of html before writeValue ever gets called. I have no idea why it does this, but we were able to fix the issue by setting this.date to a blank date in ngOnInit.

lukecolburn avatar Feb 15 '18 05:02 lukecolburn

Here is the code luke added to make it work:

//add this to your component import { DatePicker } from 'angular2-datetimepicker';

//place this in your constructor DatePicker.prototype.ngOnInit = function() { this.settings = Object.assign(this.defaultSettings, this.settings); if (this.settings.defaultOpen) { this.popover = true; } this.date = new Date(); };

Luke is a wizard.

brandon-sigao avatar Feb 15 '18 15:02 brandon-sigao

facing same issue, Please suggest right solution.

B-Tushar avatar Jun 05 '18 09:06 B-Tushar

@brandon-sigao thanks very much, this worked for me.

JohnMcAvinue avatar Jul 12 '18 13:07 JohnMcAvinue

Any news on fixing this properly?

arron21 avatar Sep 06 '18 20:09 arron21

thank you so much @brandon-sigao it works for me.

saadelshazly2020 avatar Nov 28 '18 08:11 saadelshazly2020

Thank you so much @brandon-sigao, this worked for me.

aniket-kale avatar Dec 11 '18 13:12 aniket-kale

@brandon-sigao thank you so much.

Booshna-Arthy avatar Dec 21 '18 07:12 Booshna-Arthy

@brandon-sigao thank you.

mzaman945 avatar Aug 23 '19 11:08 mzaman945

@brandon-sigao Thank you very much. This works.

deepakdhamuria avatar Oct 11 '22 05:10 deepakdhamuria