Initializes this multi-year view.
()
| 177 | |
| 178 | /** Initializes this multi-year view. */ |
| 179 | _init() { |
| 180 | this._todayYear.set(this._dateAdapter.getYear(this._dateAdapter.today())); |
| 181 | |
| 182 | // We want a range years such that we maximize the number of |
| 183 | // enabled dates visible at once. This prevents issues where the minimum year |
| 184 | // is the last item of a page OR the maximum year is the first item of a page. |
| 185 | |
| 186 | // The offset from the active year to the "slot" for the starting year is the |
| 187 | // *actual* first rendered year in the multi-year view. |
| 188 | const activeYear = this._dateAdapter.getYear(this._activeDate); |
| 189 | const minYearOfPage = |
| 190 | activeYear - getActiveOffset(this._dateAdapter, this.activeDate, this.minDate, this.maxDate); |
| 191 | |
| 192 | const years: MatCalendarCell[][] = []; |
| 193 | for (let i = 0, row: number[] = []; i < yearsPerPage; i++) { |
| 194 | row.push(minYearOfPage + i); |
| 195 | if (row.length == yearsPerRow) { |
| 196 | years.push(row.map(year => this._createCellForYear(year))); |
| 197 | row = []; |
| 198 | } |
| 199 | } |
| 200 | this._years.set(years); |
| 201 | this._changeDetectorRef.markForCheck(); |
| 202 | } |
| 203 | |
| 204 | /** Handles when a new year is selected. */ |
| 205 | _yearSelected(event: MatCalendarUserEvent<number>) { |
no test coverage detected