components icon indicating copy to clipboard operation
components copied to clipboard

MdTabGroup uses window which is not defined in node context when doing server side rendering

Open mkhurramali opened this issue 10 years ago • 3 comments

Bug, feature request, or proposal:

Bug

What is the expected behavior?

MdTabGroup should render without error when doing server side rendering

What is the current behavior?

The following exception occurs:

EXCEPTION: window.requestAnimationFrame is not a function

This is the problematic code:

ngAfterViewChecked(): void {
    this._zone.runOutsideAngular(() => {
      window.requestAnimationFrame(() => {
        this._updateInkBar();
      });
    });
    this._isInitialized = true;
 }

What are the steps to reproduce?

Server side rendering of MdTabGroup.

What is the use-case or motivation for changing an existing behavior?

Allow for server side rendering when using MdTabGroup.

Which versions of Angular, Material, OS, browsers are affected?

Angular: 2.0.1 Material: 2.0.0-alpha.8-2

Is there anything else we should know?

Here is the proposed fix:

ngAfterViewChecked(): void {
    this._zone.runOutsideAngular(() => {
      if ( typeof window.requestAnimationFrame !== 'undefined' ) {
        window.requestAnimationFrame(() => {
          this._updateInkBar();
        });
      } else {
        this._updateInkBar();
      }
    });
    this._isInitialized = true;
 }

mkhurramali avatar Oct 08 '16 16:10 mkhurramali

This fixed it for me. https://github.com/angular/material2/issues/308#issuecomment-252806444

johnnysainz avatar Oct 11 '16 04:10 johnnysainz

Thank you! That works.

mkhurramali avatar Oct 12 '16 17:10 mkhurramali

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.