diff --git a/src/datepicker/datepicker.js b/src/datepicker/datepicker.js index 0716a926b9..9baaa78736 100644 --- a/src/datepicker/datepicker.js +++ b/src/datepicker/datepicker.js @@ -98,6 +98,10 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst this.init = function(ngModelCtrl_) { ngModelCtrl = ngModelCtrl_; + if (ngModelCtrl.$modelValue) { + this.activeDate = ngModelCtrl.$modelValue; + } + ngModelCtrl.$render = function() { self.render(); }; diff --git a/src/datepicker/test/datepicker.spec.js b/src/datepicker/test/datepicker.spec.js index 0f295f2ced..19be95da52 100644 --- a/src/datepicker/test/datepicker.spec.js +++ b/src/datepicker/test/datepicker.spec.js @@ -205,6 +205,26 @@ describe('datepicker', function() { $templateCache = _$templateCache_; })); + describe('with no initial date', function() { + beforeEach(function() { + jasmine.clock().install(); + }); + + afterEach(function() { + jasmine.clock().uninstall(); + }); + + it('should have an active date equal to the current date', function() { + var baseTime = new Date(2015, 2, 23); + jasmine.clock().mockDate(baseTime); + + element = $compile('')($rootScope); @@ -243,6 +263,10 @@ describe('datepicker', function() { expect($rootScope.date).toEqual(new Date('September 30, 2010 15:30:00')); }); + it('has activeDate value of model', function() { + expect(element.controller('uibDatepicker').activeDate).toEqual(new Date('September 30, 2010 15:30:00')); + }); + it('has `selected` only the correct day', function() { expectSelectedElement(32); });