|
36 | 36 | angular.module('material.components.datepicker')
|
37 | 37 | .directive('mdCalendar', calendarDirective);
|
38 | 38 |
|
39 |
| - // POST RELEASE |
40 | 39 | // TODO(jelbourn): Mac Cmd + left / right == Home / End
|
41 | 40 | // TODO(jelbourn): Refactor month element creation to use cloneNode (performance).
|
42 | 41 | // TODO(jelbourn): Define virtual scrolling constants (compactness) users can override.
|
|
52 | 51 | function calendarDirective(inputDirective) {
|
53 | 52 | return {
|
54 | 53 | template: function(tElement, tAttr) {
|
| 54 | + // This allows the calendar to work, without a datepicker. This ensures that the virtual |
| 55 | + // repeater scrolls to the proper place on load by deferring the execution until the next |
| 56 | + // digest. It's necessary only if the calendar is used without a datepicker, otherwise it's |
| 57 | + // already wrapped in an ngIf. |
| 58 | + var extraAttrs = tAttr.hasOwnProperty('ngIf') ? '' : 'ng-if="calendarCtrl.isInitialized"'; |
55 | 59 | return '' +
|
56 |
| - '<div ng-switch="calendarCtrl.currentView">' + |
| 60 | + '<div ng-switch="calendarCtrl.currentView" ' + extraAttrs + '>' + |
57 | 61 | '<md-calendar-year ng-switch-when="year"></md-calendar-year>' +
|
58 | 62 | '<md-calendar-month ng-switch-default></md-calendar-month>' +
|
59 | 63 | '</div>';
|
|
151 | 155 | this.today = this.dateUtil.createDateAtMidnight();
|
152 | 156 |
|
153 | 157 | /** @type {!ngModel.NgModelController} */
|
154 |
| - this.ngModelCtrl = null; |
| 158 | + this.ngModelCtrl = undefined; |
155 | 159 |
|
156 | 160 | /** @type {string} Class applied to the selected date cell. */
|
157 | 161 | this.SELECTED_DATE_CLASS = 'md-calendar-selected-date';
|
|
162 | 166 | /** @type {string} Class applied to the focused cell. */
|
163 | 167 | this.FOCUSED_DATE_CLASS = 'md-focus';
|
164 | 168 |
|
165 |
| - /** @final {number} Unique ID for this calendar instance. */ |
| 169 | + /** |
| 170 | + * @final |
| 171 | + * @type {number} Unique ID for this calendar instance. |
| 172 | + */ |
166 | 173 | this.id = nextUniqueId++;
|
167 | 174 |
|
168 | 175 | /**
|
|
203 | 210 | */
|
204 | 211 | this.lastRenderableDate = null;
|
205 | 212 |
|
| 213 | + /** |
| 214 | + * Used to toggle initialize the root element in the next digest. |
| 215 | + * @type {boolean} |
| 216 | + */ |
| 217 | + this.isInitialized = false; |
| 218 | + |
206 | 219 | /**
|
207 | 220 | * Cache for the width of the element without a scrollbar. Used to hide the scrollbar later on
|
208 | 221 | * and to avoid extra reflows when switching between views.
|
209 |
| - * @type {Number} |
| 222 | + * @type {number} |
210 | 223 | */
|
211 | 224 | this.width = 0;
|
212 | 225 |
|
213 | 226 | /**
|
214 | 227 | * Caches the width of the scrollbar in order to be used when hiding it and to avoid extra reflows.
|
215 |
| - * @type {Number} |
| 228 | + * @type {number} |
216 | 229 | */
|
217 | 230 | this.scrollbarWidth = 0;
|
218 | 231 |
|
|
335 | 348 | self.displayDate = self.selectedDate || self.today;
|
336 | 349 | }
|
337 | 350 | };
|
| 351 | + |
| 352 | + self.$mdUtil.nextTick(function() { |
| 353 | + self.isInitialized = true; |
| 354 | + }); |
338 | 355 | };
|
339 | 356 |
|
340 | 357 | /**
|
|
0 commit comments