Skip to content

Commit

Permalink
Improved fix for missing call of change event
Browse files Browse the repository at this point in the history
  • Loading branch information
indrimuska committed Feb 26, 2017
1 parent d9041de commit 0550250
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions src/directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ export default class Directive implements ng.IDirective {
if (nextView < 0 || nextView > maxView) {
setValue($scope.view.moment, $scope, $ctrl, $attrs);
$scope.view.update();
if ($attrs['ngModel']) $ctrl.$commitViewValue();
if ($scope.autoclose) this.$timeout($scope.view.close);
} else if (nextView >= minView) $scope.view.selected = view;
}
Expand Down Expand Up @@ -297,14 +298,7 @@ export default class Directive implements ng.IDirective {
// properties listeners
if ($attrs['ngModel'] != $attrs['momentPicker'])
$scope.$watch('value', (newValue: string, oldValue: string) => {
if (newValue !== oldValue) {
let oldModelValue = angular.copy($ctrl.$modelValue);
setValue(newValue, $scope, $ctrl, $attrs);
if (angular.isFunction($scope.change)) {
let newModelValue = angular.copy($ctrl.$modelValue);
this.$timeout(() => $scope.change({ newValue: newModelValue, oldValue: oldModelValue }), 0, false);
}
}
if (newValue !== oldValue) setValue(newValue, $scope, $ctrl, $attrs);
});
$scope.$watch(() => momentToValue($ctrl.$modelValue, $scope.format), (newViewValue, oldViewValue) => {
if (newViewValue == oldViewValue) return;
Expand All @@ -317,11 +311,11 @@ export default class Directive implements ng.IDirective {
$scope.view.render();
if (angular.isFunction($scope.change)) {
let oldModelValue = valueToMoment(oldViewValue, $scope);
this.$timeout(() => $scope.change({ newValue: newModelValue, oldValue: oldModelValue }), 0, false);
$scope.$evalAsync(() => $scope.change({ newValue: newModelValue, oldValue: oldModelValue }));
}
});
$scope.$watch(() => $ctrl.$modelValue && $ctrl.$modelValue.valueOf(), () => {
let viewMoment = ($ctrl.$modelValue || moment().locale($scope.locale)).clone();
let viewMoment = (isValidMoment($ctrl.$modelValue) ? $ctrl.$modelValue : moment().locale($scope.locale)).clone();
if (!viewMoment.isSame($scope.view.moment)) {
$scope.view.moment = viewMoment;
$scope.view.update();
Expand Down

0 comments on commit 0550250

Please sign in to comment.