ng2-ui / datetime-picker

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

error_handler.js:50 EXCEPTION: Error in ./Ng2DatetimePickerComponent class Ng2DatetimePickerComponent - inline template:34:4 caused by: moment is not defined #101

Closed cannibalcow closed 7 years ago

cannibalcow commented 7 years ago

Maybe this is not a bug. Only user error. But I can't figure out whats wrong. Updated angular from 2.2 to 2.3 and zone.js from 0.6.23 -> 0.7.2

I do not use momentjs in the project

Subscriber.js:227 Uncaught ViewWrappedError_nativeError: Error: Error in ./Ng2DatetimePickerComponent class Ng2DatetimePickerComponent - inline template:34:4 caused by: moment is not defined at ViewWrappedError.BaseError [as constructor] (http://localhost:4200/vendor.bundle.js:7135:27) [angular] at ViewWrappedError.WrappedError [as constructor] (http://localhost:4200/vendor.bundle.js:7192:16) [angular] at new ViewWrappedError (http://localhost:4200/vendor.bundle.js:61893:16) [angular] at View_Ng2DatetimePickerComponent6.DebugAppView._rethrowWithContext (http://localhost:4200/vendor.bundle.js:85540:23) [angular] at View_Ng2DatetimePickerComponent6. (http://localhost:4200/vendor.bundle.js:85557:23) [angular] at HTMLDivElement. (http://localhost:4200/vendor.bundle.js:47949:53) [angular] at Object.onInvokeTask (http://localhost:4200/vendor.bundle.js:32485:37) [angular] at ZoneDelegate.invokeTask (http://localhost:4200/vendor.bundle.js:110992:40) [angular] at Zone.runTask (http://localhost:4200/vendor.bundle.js:110869:47) [ => angular] at HTMLDivElement.ZoneTask.invoke (http://localhost:4200/vendor.bundle.js:111063:33) []context: DebugContext_nodeIndex: 0_staticNodeInfo: (...)_tplCol: 4_tplRow: 34_view: View_Ng2DatetimePickerComponent6component: (...)componentRenderElement: (...)context: (...)injector: (...)providerTokens: (...)references: (...)renderNode: (...)source: (...)proto: Objectmessage: (...)name: (...)originalError: ReferenceError: moment is not defined at Function.Ng2Datetime.formatDate (http://localhost:4200/vendor.bundle.js:36074:23) at Ng2DatetimePickerDirective.getFormattedDateStr (http://localhost:4200/vendor.bundle.js:70269:43) at Ng2DatetimePickerDirective.valueChanged (http://localhost:4200/vendor.bundle.js:70059:36) at SafeSubscriber.schedulerFn [as _next] (http://localhost:4200/vendor.bundle.js:44551:36) at SafeSubscriber.tryOrUnsub (http://localhost:4200/vendor.bundle.js:566:16) at SafeSubscriber.next (http://localhost:4200/vendor.bundle.js:515:22) at Subscriber._next (http://localhost:4200/vendor.bundle.js:468:26) at Subscriber.next (http://localhost:4200/vendor.bundle.js:432:18) at EventEmitter.Subject.next (http://localhost:4200/vendor.bundle.js:4493:25) at EventEmitter.emit (http://localhost:4200/vendor.bundle.js:44525:76) at Ng2DatetimePickerComponent.selectDateTime (http://localhost:4200/vendor.bundle.js:49469:24) at View_Ng2DatetimePickerComponent6.handleEvent_0 (/Ng2DatetimePickerModule/Ng2DatetimePickerComponent/component.ngfactory.js:410:56) at View_Ng2DatetimePickerComponent6. (http://localhost:4200/vendor.bundle.js:85554:37) at HTMLDivElement. (http://localhost:4200/vendor.bundle.js:47949:53) at ZoneDelegate.invokeTask (http://localhost:4200/vendor.bundle.js:110993:35)stack: (...)proto__: WrappedError

cannibalcow commented 7 years ago

My bad. I had defined a date format but not provided moment. Strange that it worked in previous versions.

vsehrawat commented 7 years ago

I have included momemt js in my angular 2 project. Still I get the above error while selecting Ng2DatetimePickerComponent. How did you resolve it?

cannibalcow commented 7 years ago

Sorry, can't help you. I'll reopen the issue so that someone else can answer it.

The default format was good enough for me so I didn't define any format. I figured out that the default format never use momemt js.

allenhwkim commented 7 years ago

@vsehrawat You should include it in <script> tag, not with import as you see in this example, https://github.com/ng2-ui/ng2-datetime-picker/blob/master/app/index.html#L7