diff --git a/src/datepicker/datepicker.js b/src/datepicker/datepicker.js index 691f6e05bd..f8cdf1279f 100644 --- a/src/datepicker/datepicker.js +++ b/src/datepicker/datepicker.js @@ -30,7 +30,7 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst self[key] = angular.isDefined($attrs[key]) ? (index < 8 ? $interpolate($attrs[key])($scope.$parent) : $scope.$parent.$eval($attrs[key])) : datepickerConfig[key]; }); - // Watchable attributes + // Watchable date attributes angular.forEach(['minDate', 'maxDate'], function( key ) { if ( $attrs[key] ) { $scope.$parent.$watch($parse($attrs[key]), function(value) { @@ -477,12 +477,24 @@ function ($compile, $parse, $document, $position, dateFilter, dateParser, datepi }); } - angular.forEach(['minDate', 'maxDate'], function( key ) { + scope.watchData = {}; + angular.forEach(['minDate', 'maxDate', 'datepickerMode'], function( key ) { if ( attrs[key] ) { - scope.$parent.$watch($parse(attrs[key]), function(value){ - scope[key] = value; + var getAttribute = $parse(attrs[key]); + scope.$parent.$watch(getAttribute, function(value){ + scope.watchData[key] = value; }); - datepickerEl.attr(cameltoDash(key), key); + datepickerEl.attr(cameltoDash(key), 'watchData.' + key); + + // Propagate changes from datepicker to outside + if ( key === 'datepickerMode' ) { + var setAttribute = getAttribute.assign; + scope.$watch('watchData.' + key, function(value, oldvalue) { + if ( value !== oldvalue ) { + setAttribute(scope.$parent, value); + } + }); + } } }); if (attrs.dateDisabled) { diff --git a/src/datepicker/docs/demo.js b/src/datepicker/docs/demo.js index d6cb4eeb3b..21e440811a 100644 --- a/src/datepicker/docs/demo.js +++ b/src/datepicker/docs/demo.js @@ -30,7 +30,6 @@ angular.module('ui.bootstrap.demo').controller('DatepickerDemoCtrl', function ($ startingDay: 1 }; - $scope.initDate = new Date('2016-15-20'); $scope.formats = ['dd-MMMM-yyyy', 'yyyy/MM/dd', 'dd.MM.yyyy', 'shortDate']; $scope.format = $scope.formats[0]; }); diff --git a/src/datepicker/test/datepicker.spec.js b/src/datepicker/test/datepicker.spec.js index 90f9e74d18..1eb14a434d 100644 --- a/src/datepicker/test/datepicker.spec.js +++ b/src/datepicker/test/datepicker.spec.js @@ -1597,6 +1597,25 @@ describe('datepicker directive', function () { } }); }); + + describe('`datepicker-mode`', function () { + beforeEach(inject(function() { + $rootScope.date = new Date('August 11, 2013'); + $rootScope.mode = 'month'; + wrapElement = $compile('
')($rootScope); + $rootScope.$digest(); + assignElements(wrapElement); + })); + + it('shows the correct title', function() { + expect(getTitle()).toBe('2013'); + }); + + it('updates binding', function() { + clickTitleButton(); + expect($rootScope.mode).toBe('year'); + }); + }); }); describe('with empty initial state', function () {