Skip to content
This repository was archived by the owner on May 29, 2019. It is now read-only.

Commit 1b888d4

Browse files
committed
fix(datepicker): dereference date initialization
- Dereference the date set to active date to prevent model automatically updating from equal reference Closes #5643 Fixes #5441
1 parent 5ef56e2 commit 1b888d4

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/datepicker/datepicker.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,9 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
271271
ngModelCtrl = ngModelCtrl_;
272272
ngModelOptions = ngModelCtrl_.$options || datepickerConfig.ngModelOptions;
273273

274-
this.activeDate = ngModelCtrl.$modelValue || new Date();
274+
this.activeDate = ngModelCtrl.$modelValue ?
275+
dateParser.fromTimezone(new Date(ngModelCtrl.$modelValue), ngModelOptions.timezone) :
276+
dateParser.fromTimezone(new Date(), ngModelOptions.timezone);
275277

276278
ngModelCtrl.$render = function() {
277279
self.render();

src/datepicker/test/datepicker.spec.js

+7
Original file line numberDiff line numberDiff line change
@@ -1828,6 +1828,13 @@ describe('datepicker', function() {
18281828
expect(getTitle()).toBe('January 2014');
18291829
});
18301830

1831+
it('should not change model when going to next month - #5441', function() {
1832+
$rootScope.date = new Date('January 30, 2014');
1833+
$rootScope.$digest();
1834+
clickNextButton();
1835+
expect($rootScope.date).toEqual(new Date('January 30, 2014'));
1836+
});
1837+
18311838
describe('when `model` changes', function() {
18321839
function testCalendar() {
18331840
expect(getTitle()).toBe('November 2005');

0 commit comments

Comments
 (0)