From c5b63ded0aebd7ae80f238bd0a33f1d9c0746dba Mon Sep 17 00:00:00 2001 From: Winckell Thomas Date: Thu, 10 Jul 2014 15:01:11 +0200 Subject: [PATCH] fix(datepicker): Fix init-date not applying on datepicker-popup Fix of the init-date attribute for the datepicker-popup. The init-date attribute, when set in a datepicker-popup element, is now added to the datepicker element and in the datepicker-popup scope, so the datepicker element can retrieve the attribute value. --- src/datepicker/datepicker.js | 4 ++++ src/datepicker/test/datepicker.spec.js | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/datepicker/datepicker.js b/src/datepicker/datepicker.js index 577979d724..953e42b392 100644 --- a/src/datepicker/datepicker.js +++ b/src/datepicker/datepicker.js @@ -510,6 +510,10 @@ function ($compile, $parse, $document, $position, dateFilter, dateParser, datepi if (attrs.customClass){ datepickerEl.attr('custom-class', 'customClass({ date: date, mode: mode })'); } + if (attrs.initDate) { + scope.initDate = scope.$parent.$eval(attrs.initDate); + datepickerEl.attr('init-date', 'initDate'); + } function parseDate(viewValue) { if (angular.isNumber(viewValue)) { diff --git a/src/datepicker/test/datepicker.spec.js b/src/datepicker/test/datepicker.spec.js index 84eaac7630..c4cedb1f05 100644 --- a/src/datepicker/test/datepicker.spec.js +++ b/src/datepicker/test/datepicker.spec.js @@ -1708,6 +1708,25 @@ describe('datepicker directive', function () { expect($rootScope.mode).toBe('year'); }); }); + + describe('attribute `initDate`', function () { + var weekHeader, weekElement; + beforeEach(function() { + $rootScope.date = null; + $rootScope.initDate = new Date('November 9, 1980'); + var wrapElement = $compile('
')($rootScope); + $rootScope.$digest(); + assignElements(wrapElement); + }); + + it('should not alter the model', function() { + expect($rootScope.date).toBe(null); + }); + + it('shows the correct title', function() { + expect(getTitle()).toBe('November 1980'); + }); + }); }); describe('with empty initial state', function () {