ng2-ui / datetime-picker

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

EXCEPTION: moment is not defined #121

Closed enheit closed 7 years ago

enheit commented 7 years ago

Hello, i have faced with an issue after your last update.

Could you explain me how to prevent this error message?

P.S. In version 0.12.0 i had no troubles. P.S.S. I've noticed subject with the same error https://github.com/ng2-ui/ng2-datetime-picker/issues/120

`EXCEPTION: moment is not defined
ErrorHandler.handleError @ core.umd.js?e2a5:3491
next @ core.umd.js?e2a5:8449
schedulerFn @ core.umd.js?e2a5:4118
SafeSubscriber.__tryOrUnsub @ VM7402:223
SafeSubscriber.next @ VM7402:172
Subscriber._next @ VM7402:125
Subscriber.next @ VM7402:89
Subject.next @ VM7398:55
EventEmitter.emit @ core.umd.js?e2a5:4104
NgZone.triggerError @ core.umd.js?e2a5:4465
onHandleError @ core.umd.js?e2a5:4426
ZoneDelegate.handleError @ zone.js?fad3:233
Zone.runTask @ zone.js?fad3:154
ZoneTask.invoke @ zone.js?fad3:332
core.umd.js?e2a5:3496 ORIGINAL STACKTRACE:
ErrorHandler.handleError @ core.umd.js?e2a5:3496
next @ core.umd.js?e2a5:8449
schedulerFn @ core.umd.js?e2a5:4118
SafeSubscriber.__tryOrUnsub @ VM7402:223
SafeSubscriber.next @ VM7402:172
Subscriber._next @ VM7402:125
Subscriber.next @ VM7402:89
Subject.next @ VM7398:55
EventEmitter.emit @ core.umd.js?e2a5:4104
NgZone.triggerError @ core.umd.js?e2a5:4465
onHandleError @ core.umd.js?e2a5:4426
ZoneDelegate.handleError @ zone.js?fad3:233
Zone.runTask @ zone.js?fad3:154
ZoneTask.invoke @ zone.js?fad3:332
core.umd.js?e2a5:3497 ReferenceError: moment is not defined
    at Ng2DatetimePickerComponent.initDatetime (eval at <anonymous> (http://localhost:9000/app.bundle.js:209:2), <anonymous>:351:22)
    at Ng2DatetimePickerDirective.showDatetimePicker (eval at <anonymous> (http://localhost:9000/app.bundle.js:209:2), <anonymous>:727:20)
    at Wrapper_Ng2DatetimePickerDirective.handleEvent (/Ng2DatetimePickerModule/Ng2DatetimePickerDirective/wrapper.ngfactory.js:191:34)
    at View_EtlScheduleComponent2.handleEvent_16 (/AppModule/EtlScheduleComponent/component.ngfactory.js:558:52)
    at View_EtlScheduleComponent2.eval (eval at <anonymous> (http://localhost:9000/vendor.bundle.js:136:2), <anonymous>:12778:41)
    at HTMLInputElement.eval (eval at <anonymous> (http://localhost:9000/vendor.bundle.js:244:2), <anonymous>:3216:55)
    at ZoneDelegate.invokeTask (eval at <anonymous> (http://localhost:9000/polyfills.bundle.js:3158:2), <anonymous>:262:35)
    at Object.onInvokeTask (eval at <anonymous> (http://localhost:9000/vendor.bundle.js:136:2), <anonymous>:4396:41)
    at ZoneDelegate.invokeTask (eval at <anonymous> (http://localhost:9000/polyfills.bundle.js:3158:2), <anonymous>:261:40)
    at Zone.runTask (eval at <anonymous> (http://localhost:9000/polyfills.bundle.js:3158:2), <anonymous>:151:47)
    at HTMLInputElement.ZoneTask.invoke (eval at <anonymous> (http://localhost:9000/polyfills.bundle.js:3158:2), <anonymous>:332:33)`
allenhwkim commented 7 years ago

0.12.9 releases, please verify. Duplicate to #120

akbarjan commented 6 years ago

IN ANGULAR 2 SOLUTION IS ADD THE FOLLOWING TO app.module.ts // Override Date object formatter Ng2Datetime.formatDate = (date: Date) : string => { if (!date) return '';

    let m = date.getMonth() + 1;
    let maand = m < 10 ? '0' + m : m;

    let d = date.getDate();
    let dag = d < 10 ? '0' + d : d;

        return [dag, maand, date.getFullYear()].join('-');

};

// Override Date object parser Ng2Datetime.parseDate = (str: any): Date => { return new Date(str); };

Ng2Datetime.firstDayOfWeek = 1;

Ng2Datetime.daysOfWeek = [ { fullName: 'Zondag', shortName: 'Zo', weekend: true }, { fullName: 'Maandag', shortName: 'Ma' }, { fullName: 'Dinsdag', shortName: 'Di' }, { fullName: 'Woensdag', shortName: 'Wo' }, { fullName: 'Donderdag', shortName: 'Do' }, { fullName: 'Vrijdag', shortName: 'Vr' }, { fullName: 'Zaterdag', shortName: 'Za', weekend: true } ];

Ng2Datetime.months = [ { fullName: 'Januari', shortName: 'Jan' }, { fullName: 'Februari', shortName: 'Feb' }, { fullName: 'Maart', shortName: 'Maa' }, { fullName: 'April', shortName: 'Apr' }, { fullName: 'Mei', shortName: 'Mei' }, { fullName: 'Juni', shortName: 'Jun' }, { fullName: 'Juli', shortName: 'Jul' }, { fullName: 'Augustus', shortName: 'Aug' }, { fullName: 'September', shortName: 'Sep' }, { fullName: 'Oktober', shortName: 'Okt' }, { fullName: 'November', shortName: 'Nov' }, { fullName: 'December', shortName: 'Dec' }, ];