classlinkinc / angular-material-time-picker

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

ng-change not working #13

Open nmsan opened 7 years ago

Andreasbaaserud commented 7 years ago

Could you please provide some more information about the issue?

  1. Console output?
  2. What are you trying to achieve?
mkoutroupis commented 7 years ago

Same for me.. https://codepen.io/Koutroupis/pen/MoZYKB

Andreasbaaserud commented 7 years ago

I still can't see what is the error. What are you trying to achieve?

Andreasbaaserud commented 7 years ago

I will close this issue in lack of description. If issue still presist, please provide steps to reproduce and I will reopen the issue.

mkoutroupis commented 7 years ago

I am trying to make a directive with your time picker. Whenever there is a change in the value I want to handle this change. I thought this would be possible if I add a function on the data-ng-change event but it's not triggered at all!

Andreasbaaserud commented 7 years ago

Thanks for your comment. ng-change is not yet supported. This should be added

mkoutroupis commented 7 years ago

Great news then! Any other way that I can programmatically be informed about the change in the date?

Andreasbaaserud commented 7 years ago

You could use $watch in $scope https://docs.angularjs.org/api/ng/type/$rootScope.Scope I would be carefull to use it, too many digests and you can end up with a slow performing application.

$scope.$watch('value', function() { // call something });

sebius8780 commented 6 years ago

you also have a mdpTimePickerUpdated event emitted. I am planning to make a pull request for the ngChnage call is that ok with you ?

sebius8780 commented 6 years ago

created a ng-change compatibility PR for this, hope this is ok with you ? Thank you for you lib !

gaganpreets commented 6 years ago

Hi can u plz tell me, How can detect changes in time ?

sebius8780 commented 6 years ago

@gaganpreets please check my fork you will have a ngChange parameter.

gaganpreets commented 6 years ago

I am using following code , I didn't get any changes in dateChanges function. Please let me know if I am wrong.

<md-time-picker ng-model="model.endTime" ng-change="dateChanges($event)"
                            name="endTime"></md-time-picker>

$scope.dateChanges = function(event){
            console.log("Date Changed")
            console.log(event)
        };
RNandeZ commented 6 years ago

I used this pluggin some weeks ago for the simplicity of its interface (coupled with angular-moment for the date formatting inside template). And to watch any changes, as ng-change is not supported yet by the pluggin, I created a custom directive like so:

<md-time-picker 
    no-meridiem 
    ng-model="myDateStringModel" 
    name="myName" 
    watch-time-change="{{myDateStringModel | amDateFormat:'HH:mm'}}">
</md-time-picker>
    angular
        .module('myModule')
        .directive('watchTimeChange', watchTimeChange);

    function watchTimeChange($timeout) {
      return {
        restrict: 'A',
        link: function(scope, element, attrs) {
          attrs.$observe('watchTimeChange', function(newTime) {
            $timeout(function() {
              //Use your newTime variable here
            }, 0);
          });
        });
      };
    }

PS: the filter 'amDateFormat' is not mandatory, I just needed to display a Date in this format.

Hope this could help.

sebius8780 commented 6 years ago

@gaganpreets my fork is there : https://github.com/sebius8780/angular-material-time-picker Good luck !