Skip to content

bug(datepicker/mat-calendar): ERROR ReferenceError: window is not defined #26729

Closed
@evheniyrz

Description

@evheniyrz

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

13.x

Description

I use the date picker in calendar mode in the sidebar on the main page. the component is initialized when the application is loaded.
After upgrading from version 13.x to 14.x and after to 15.x I get an error in the console. But the application starts up and the calendar works

<mat-calendar
  (selectedChange)="dateChange($event)"
  [(selected)]="selectedDate"
  [dateClass]="dateStyleFn"
  class="app-calendar"></mat-calendar>

Reproduction

Steps to reproduce:

  1. Angular Universal (SSR) project
  2. npm run dev:ssr

Expected Behavior

no error

Actual Behavior

ERROR ReferenceError: window is not defined
at apply (./node_modules/@angular/material/fesm2020/datepicker.mjs:289:13)
at invoke (./node_modules/zone.js/dist/zone-node.js:400:30)
at run (./node_modules/zone.js/dist/zone-node.js:160:47)
at runOutsideAngular (./node_modules/@angular/core/fesm2020/core.mjs:24137:28)
at constructor (./node_modules/@angular/material/fesm2020/datepicker.mjs:280:17)
at factory (./node_modules/@angular/material/fesm2020/datepicker.mjs:492:21)
at getNodeInjectable (./node_modules/@angular/core/fesm2020/core.mjs:3484:44)
at instantiateAllDirectives (./node_modules/@angular/core/fesm2020/core.mjs:11038:27)
at createDirectivesInstances (./node_modules/@angular/core/fesm2020/core.mjs:10511:5)
at Module.ɵɵelementStart (./node_modules/@angular/core/fesm2020/core.mjs:13641:9)

Environment

  • Angular: ~15.2.1
  • CDK/Material: ^15.2.1
  • Browser(s): Crome
  • Operating System (e.g. Windows, macOS, Ubuntu): Windows 10 64-bit

Metadata

Metadata

Assignees

Labels

P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentarea: material/datepicker

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions