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

Commit

Permalink
fix(datepicker): dereference date initialization
Browse files Browse the repository at this point in the history
- Dereference the date set to active date to prevent model automatically
  updating from equal reference

Closes #5643
Fixes #5441
  • Loading branch information
wesleycho committed Mar 18, 2016
1 parent 5ef56e2 commit 1b888d4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/datepicker/datepicker.js
Expand Up @@ -271,7 +271,9 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
ngModelCtrl = ngModelCtrl_;
ngModelOptions = ngModelCtrl_.$options || datepickerConfig.ngModelOptions;

this.activeDate = ngModelCtrl.$modelValue || new Date();
this.activeDate = ngModelCtrl.$modelValue ?
dateParser.fromTimezone(new Date(ngModelCtrl.$modelValue), ngModelOptions.timezone) :
dateParser.fromTimezone(new Date(), ngModelOptions.timezone);

ngModelCtrl.$render = function() {
self.render();
Expand Down
7 changes: 7 additions & 0 deletions src/datepicker/test/datepicker.spec.js
Expand Up @@ -1828,6 +1828,13 @@ describe('datepicker', function() {
expect(getTitle()).toBe('January 2014');
});

it('should not change model when going to next month - #5441', function() {
$rootScope.date = new Date('January 30, 2014');
$rootScope.$digest();
clickNextButton();
expect($rootScope.date).toEqual(new Date('January 30, 2014'));
});

describe('when `model` changes', function() {
function testCalendar() {
expect(getTitle()).toBe('November 2005');
Expand Down

0 comments on commit 1b888d4

Please sign in to comment.