jfmdev / ngComboDatePicker

Angular directive to select dates using combo boxes
Mozilla Public License 2.0
23 stars 20 forks source link

New Feature Request : Can we have ng-change event for same? #42

Closed Suresh-Lakum closed 6 years ago

Suresh-Lakum commented 6 years ago

Hello,

I am struggling with ng-change. It will be great if we have ng-change for ngComboDatePicker. Much appreciated.

Kind Regards.

jfmdev commented 6 years ago

Hi Suresh,

As a replacement for ng-change, have you tried watching the value of the model?

For example:

<script type="text/javascript">
    var app = angular.module('myApp',['ngComboDatePicker']);
    app.controller('basicCtrl', function ($scope) {
        $scope.basic = new Date();
        $scope.$watch('basic', function(newValue, oldValue) {
            if(newValue !== oldValue) {
                console.log('The date was changed!');
            }
        });
    });
</script>
<div ng-app="myApp" ng-controller="basicCtrl">
    <p>Choose a date: <ng-combo-date-picker ng-model="basic"></ng-combo-date-picker></p>
</div>

Regards

Suresh-Lakum commented 6 years ago

Hi,

Yes that's the wise solution. But consider scenario where I have collection of objects and among them I have one date field, I have to iterate through objects and then add watch to it. Which is I think not a best practice. So in that case if I have ngChange event or ngBlur event it will be good.

Hopefully you got my point.

Kind regards, Suresh

jfmdev commented 6 years ago

Hi Suresh,

I have just made release 1.6.0 implementing the ng-change attribute.
Please, let me know if it works as expected.

Regards

Suresh-Lakum commented 6 years ago

Thanks.