Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Webpack #52

Open
jolic opened this issue May 17, 2016 · 15 comments
Open

Webpack #52

jolic opened this issue May 17, 2016 · 15 comments

Comments

@jolic
Copy link

jolic commented May 17, 2016

How can md-date-time-picker be used with Webpack? Any examples?

@jolic
Copy link
Author

jolic commented May 17, 2016

Got it:

import mdDateTimePicker from "md-date-time-picker";
...
var dateDialog = new mdDateTimePicker({
  type: 'date'
});

@puranjayjain
Copy link
Owner

@jolic also the new keyword will be like this in v2.0.0

var dialog = new mdDateTimePicker.default({
        type: 'date'
});

Feel free to close this issue if it is resolved 😄

@jolic
Copy link
Author

jolic commented May 17, 2016

I'm just inspecting the source and I think it would be better to provide callbacks on the constructor:

var dateDialog = new mdDateTimePicker({
  type: "date"
  ,past: moment().subtract(3, 'years')
  ,future: moment()
  ,onClick: function(date){
    console.log(date);
  }
  ,onOk: function(date){
    console.log(date);
  }
  ,onCancel: function(date){
    console.log(date);
  }
});
...

function mdDateTimePicker(_ref) {
...
                    _ref$onClick = _ref.onClick,
                onClick = _ref$onClick === undefined ? '' : _ref$onClick,
                    _ref$onOk = _ref.onOk,
                onOk = _ref$onOk === undefined ? '' : _ref$onOk,
                    _ref$onCancel = _ref.onCancel,
                onCancel = _ref$onCancel === undefined ? '' : _ref$onCancel;
...
            this._onClick = onClick;
            this._onOk = onOk;
            this._onCancel = onCancel;
...
            value: function _addCellClickEvent(el) {
...
                        // update temp date object with the date selected
                        me._sDialog.sDate = currentDate.clone();
                        if (me._onClick) {
                            me._onClick(me._sDialog.sDate);
                        }
                        me._fillText(subtitle, currentDate.year());
....

@jolic
Copy link
Author

jolic commented May 17, 2016

With this you didn't depend on an element and it's clearer for the user...
What do you think?

@jolic
Copy link
Author

jolic commented May 17, 2016

Maybe it would be nice to contribute the datepicker to https://github.com/tleunen/react-mdl

@puranjayjain
Copy link
Owner

@jolic i'll start a pr there in some time for the component (possibly two of them)

About the callbacks can you start a PR?

@puranjayjain
Copy link
Owner

@jolic also if possible can this callback solution be done in a way that we don't have any breaking changes?

Also, how does react mdl differ from material ui? Any ideas?

@PhilippeOberti
Copy link

hey guys, quick question: I'm using datetime picker in a project with Webpack. in my vendor.ts file I load moment and the datetime picker as follow

import 'moment';
import 'md-date-time-picker';

then in my angular2 component I'm using moment and the datetime picker like this

let moment = require('moment');
let mdDateTimePicker = require('md-date-time-picker');

From my angular2 component I can use moment no problem but as soon as I initialize the datetime picker

var dialog = new mdDateTimePicker.default({
    type: 'date'
});

it throws an exception

picker

any idea?
thanks a lot!!

Philippe

@puranjayjain
Copy link
Owner

puranjayjain commented May 28, 2016

@filoucpp you need to configure webpack as done here:
https://webpack.github.io/docs/library-and-externals.html

or modify your require statements as

window.moment = require('moment');
const mdDateTimePicker = require('md-date-time-picker');

@puranjayjain puranjayjain removed the bug label May 28, 2016
@PhilippeOberti
Copy link

PhilippeOberti commented May 31, 2016

thanks for the answer, the only way I got it working was to write this:

(<any> window).moment = require('moment');

once somewhere in the code, and then in every file that uses moment do this

declare var moment: any;

thanks for the help!!

@puranjayjain
Copy link
Owner

@filoucpp congrats it worked for you and thanks for posting the answer too! It would help a lot of people in the future 😄

@DenysVuika
Copy link

Could you please provide a clear example on using with code splitting and webpack? Tried numerous approaches and md-date-time-picker just does not work.

vendors.ts
css seems to be working:

import 'md-date-time-picker/dist/css/mdDateTimePicker.css';

not working

import 'md-date-time-picker';
import 'md-date-time-picker/dist/js/mdDateTimePicker.min.js';
require('md-date-time-picker');

Thanks in advance

@puranjayjain
Copy link
Owner

Hmm seems to be an issue

@DenysVuika
Copy link

Any updates on the issue?

@puranjayjain
Copy link
Owner

Cant say yet will try my best to release it asap.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants