Skip to content

Commit 0db03a1

Browse files
thomaswinckellayakovlevgh
authored andcommitted
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.
1 parent b3967bf commit 0db03a1

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/datepicker/datepicker.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,10 @@ function ($compile, $parse, $document, $position, dateFilter, dateParser, datepi
510510
if (attrs.customClass){
511511
datepickerEl.attr('custom-class', 'customClass({ date: date, mode: mode })');
512512
}
513+
if (attrs.initDate) {
514+
scope.initDate = scope.$parent.$eval(attrs.initDate);
515+
datepickerEl.attr('init-date', 'initDate');
516+
}
513517

514518
function parseDate(viewValue) {
515519
if (angular.isNumber(viewValue)) {

src/datepicker/test/datepicker.spec.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1708,6 +1708,25 @@ describe('datepicker directive', function () {
17081708
expect($rootScope.mode).toBe('year');
17091709
});
17101710
});
1711+
1712+
describe('attribute `initDate`', function () {
1713+
var weekHeader, weekElement;
1714+
beforeEach(function() {
1715+
$rootScope.date = null;
1716+
$rootScope.initDate = new Date('November 9, 1980');
1717+
var wrapElement = $compile('<div><input ng-model="date" datepicker-popup init-date="initDate" is-open="true"></div>')($rootScope);
1718+
$rootScope.$digest();
1719+
assignElements(wrapElement);
1720+
});
1721+
1722+
it('should not alter the model', function() {
1723+
expect($rootScope.date).toBe(null);
1724+
});
1725+
1726+
it('shows the correct title', function() {
1727+
expect(getTitle()).toBe('November 1980');
1728+
});
1729+
});
17111730
});
17121731

17131732
describe('with empty initial state', function () {

0 commit comments

Comments
 (0)