angularjsangular-daterangepicker

moment is not defined angular moment picker


I have used 'Angular-Moment-Picker' for implementig date Picker with Angular1.6 and facing console error 'Moment is not defined' after importing required Module.

Official website for Angular-Moment-Picker: https://indrimuska.github.io/angular-moment-picker/

Error:

enter image description here

I have added module as per below. 1. I have installed 'Angular-Moment-picker' and Moment using NPM iNSTALL. 2. included both modules in app.module.js file.

import momentPicker from 'angular-moment-picker';
import * as moment from 'moment/min/moment-with-locales';

Also,

const app = angular
    .module('app', [
        ...
        moment,
        momentPicker,
       ...
    ])...

Now, I am facing this error in console.

Also, I have also tried adding few things inside 'webpack-config.js' file but there is no luck on it.

new webpack.ProvidePlugin({
            moment: 'moment',
        }),

Not only that, I have also tried many things but still no luck.

It would be great, if some can help me on it.

Thanks in advance...


Solution

  • Finally, I am able to resolve this issue by manually including the 'Angular-Moment-Picker' JS file and linked to index.js file.

    app.module.js

    import './angular-moment-picker.min';
    import './moment-with-`enter code here`locales';
    import './angular-moment-picker.css';
    
    angular
        .module('app', [
    ...
                   'moment-picker',
    ....
        ])
    

    Also added file details inside index.html

    <script type="text/javascript" src="path/to/load/angular.min.js"></script>
    <script type="text/javascript" src="path/to/load/moment-with-locales.js"></script>
    <script type="text/javascript" src="path/to/load/angular-moment-picker.min.js"></script>
    

    Thanks for all for your support and help on it.