classlinkinc / angular-material-time-picker

Material design time picker for 12 and 24 hour time.
MIT License
48 stars 29 forks source link

doesn't work with es6 #22

Closed Geoffrey-Dere closed 7 years ago

Geoffrey-Dere commented 7 years ago

Hello,

sorry for my english, I will do my best. When I want to open the clock (with the dialog), I have an error.

`TypeError: [Capico Coach Error] Cannot read property 'getHours' of undefined at controller.init (md-time-picker.js:552)

(self.time is undefined)

 switch (self.type) {
              case TYPE_HOURS:
                if (self.noMeridiem) {
                  for (var i = 1; i <= 23; i++)
                    self.steps.push(i);
                  self.steps.push(0);
                  self.selected = self.time.getHours() || 0;
                }
                else {
                  for (var i = 1; i <= 12; i++)
                    self.steps.push(i);
                    self.selected = self.time.getHours() || 0;
                    if (self.selected > 12) self.selected -= 12;
                }

This problem is due to your function 'init' which is launch before the initialization of the controller

angularjs doc says this:

Deprecation warning: although bindings for non-ES6 class controllers are currently bound to this before the controller constructor is called, this use is now deprecated. Please place initialization code that relies upon bindings inside a $onInit method on the controller, instead.

To resolve the problem, I replaced your function init by the method $onInit

Andreasbaaserud commented 7 years ago

I think this is already resolved in release 1.0.7 https://github.com/classlinkinc/angular-material-time-picker/releases/tag/1.0.7

unfortunately release 1.0.7 is not yet released on npmjs.com - https://www.npmjs.com/package/angular-material-time-picker

Geoffrey-Dere commented 7 years ago

Oh ... indeed, i'm blind ..

Thx