diff --git a/demo/demo.html b/demo/demo.html index 4b68261..91a137f 100644 --- a/demo/demo.html +++ b/demo/demo.html @@ -9,23 +9,36 @@ AngularUI - Date Picker Demo - + - + +
- +
{{ aDate }}
+
Increase Date
+ +
+ diff --git a/src/date.js b/src/date.js index fd83e49..c3529f8 100644 --- a/src/date.js +++ b/src/date.js @@ -177,6 +177,20 @@ if (typeof module !== 'undefined' && typeof exports !== 'undefined' && module.ex } }; + // Watch for changes to values in the date (and not just reference changes) + scope.$watch(function() { + if (controller && angular.isDate(controller.$modelValue)) { + return controller.$modelValue.getDate(); + } else { + return null; + } + }, + function() { + if (controller) { + controller.$render(); + } + }); + // Watch for changes to the directives options scope.$watch(getOptions, initDateWidget, true); } diff --git a/test/date.spec.js b/test/date.spec.js index b22e4d5..55e9006 100644 --- a/test/date.spec.js +++ b/test/date.spec.js @@ -259,6 +259,21 @@ describe('uiDate', function() { expect(element.datepicker('getDate')).toEqual(aDate); }); }); + + it('should update the datepicker if the model changes', function() { + inject(function($compile, $rootScope) { + var aDate, element; + aDate = new Date(2010, 12, 1); + element = $compile('')($rootScope); + $rootScope.$apply(function() { + $rootScope.x = aDate; + }); + aDate.setDate(aDate.getDate() + 1); + $rootScope.$apply(); + expect(element.datepicker('getDate')).toEqual(aDate); + }); + }); + it('should put the date in the model', function() { inject(function($compile, $rootScope) { var aDate, element;