ng2-ui / datetime-picker

Angular2 DateTime Picker
https://ng2-ui.github.io/#/datetime-picker
MIT License
121 stars 62 forks source link

ng2-datetime-picker fails to bind to model when set beforehand #105

Closed kibbled closed 7 years ago

kibbled commented 7 years ago

Getting the standard error: EXCEPTION: Cannot read property 'fullName' of undefined

When I click into the date time picker.

<input id="myDateTime" name="myDateTime" [(ngModel)]="deleteMe" ng2-datetime-picker />

Thanks

allenhwkim commented 7 years ago

Thanks and No, it does not require use of reactive forms.

AFAIK, this is not possible from this line, unless you are using invalid momentjs;

https://github.com/ng2-ui/ng2-datetime-picker/blob/master/src/ng2-datetime.ts#L19

Please create a plunker example, so that I can reproduce your issue.

kibbled commented 7 years ago

Attached is what the DateTime Picker looks like:

xyz

Going through the call stack, this.el['dateValue’] is Ng2DatetimePickerDirective line 223.

If I comment out instantiation to Date() like below then it works and holds the value correctly in the model.

public deleteMe: Date;// = new Date();

Basically it doesn’t like it when I default the value of the model I’m binding to it.

allenhwkim commented 7 years ago

Nope, still not getting it. Are you using IE8 or something? I assume the following does not work for your environment.

var d  = new Date();
d.getFullYear(); // NaN instead of 2017