@@ -14,13 +14,15 @@ import {
1414 Output ,
1515 Renderer ,
1616 SimpleChange ,
17- ViewChild
17+ ViewChild ,
18+ PLATFORM_ID
1819} from '@angular/core' ;
1920import { fromEvent , interval , Subscription } from 'rxjs' ;
2021import { debounce } from 'rxjs/operators' ;
2122import { IgxNavigationService , IToggleView } from '../core/navigation' ;
2223import { HammerGesturesManager } from '../core/touch' ;
2324import { IgxNavDrawerMiniTemplateDirective , IgxNavDrawerTemplateDirective } from './navigation-drawer.directives' ;
25+ import { isPlatformBrowser } from '@angular/common' ;
2426
2527let NEXT_ID = 0 ;
2628/**
@@ -612,18 +614,26 @@ export class IgxNavigationDrawerComponent implements
612614 }
613615
614616 private getWindowWidth ( ) {
617+ if ( ! isPlatformBrowser ( PLATFORM_ID ) ) {
618+ return ;
619+ }
620+
615621 return ( window . innerWidth > 0 ) ? window . innerWidth : screen . width ;
616622 }
617623
618624 /**
619625 * Sets the drawer width.
620626 */
621627 private setDrawerWidth ( width : string ) {
622- requestAnimationFrame ( ( ) => {
623- if ( this . drawer ) {
624- this . renderer . setElementStyle ( this . drawer , 'width' , width ) ;
625- }
626- } ) ;
628+ if ( isPlatformBrowser ( PLATFORM_ID ) ) {
629+ requestAnimationFrame ( ( ) => {
630+ if ( this . drawer ) {
631+ this . renderer . setElementStyle ( this . drawer , 'width' , width ) ;
632+ }
633+ } ) ;
634+ } else {
635+ this . renderer . setElementStyle ( this . drawer , 'width' , width ) ;
636+ }
627637 }
628638
629639 /**
@@ -649,7 +659,7 @@ export class IgxNavigationDrawerComponent implements
649659 this . _touchManager . addGlobalEventListener ( 'document' , 'panmove' , this . pan ) ;
650660 this . _touchManager . addGlobalEventListener ( 'document' , 'panend' , this . panEnd ) ;
651661 }
652- if ( ! this . _resizeObserver ) {
662+ if ( ! this . _resizeObserver && isPlatformBrowser ( PLATFORM_ID ) ) {
653663 this . _resizeObserver = fromEvent ( window , 'resize' ) . pipe ( debounce ( ( ) => interval ( 150 ) ) )
654664 . subscribe ( ( value ) => {
655665 this . checkPinThreshold ( value ) ;
@@ -805,19 +815,27 @@ export class IgxNavigationDrawerComponent implements
805815 * @param opacity optional value to apply to the overlay
806816 */
807817 private setXSize ( x : number , opacity ?: string ) {
808- // Angular polyfills patches window.requestAnimationFrame, but switch to DomAdapter API (TODO)
809- window . requestAnimationFrame ( ( ) => {
810- if ( this . hasAnimateWidth ) {
811- this . renderer . setElementStyle ( this . drawer , 'width' , x ? Math . abs ( x ) + 'px' : '' ) ;
812- } else {
813- this . renderer . setElementStyle ( this . drawer , 'transform' , x ? 'translate3d(' + x + 'px,0,0)' : '' ) ;
814- this . renderer . setElementStyle ( this . drawer , '-webkit-transform' ,
815- x ? 'translate3d(' + x + 'px,0,0)' : '' ) ;
816- }
817- if ( opacity !== undefined ) {
818- this . renderer . setElementStyle ( this . overlay , 'opacity' , opacity ) ;
819- }
820- } ) ;
818+ if ( isPlatformBrowser ( PLATFORM_ID ) ) {
819+ // Angular polyfills patches window.requestAnimationFrame, but switch to DomAdapter API (TODO)
820+ window . requestAnimationFrame ( ( ) => {
821+ this . setXSizeInternal ( x , opacity ) ;
822+ } ) ;
823+ } else {
824+ this . setXSizeInternal ( x , opacity ) ;
825+ }
826+ }
827+
828+ private setXSizeInternal ( x : number , opacity ?: string ) {
829+ if ( this . hasAnimateWidth ) {
830+ this . renderer . setElementStyle ( this . drawer , 'width' , x ? Math . abs ( x ) + 'px' : '' ) ;
831+ } else {
832+ this . renderer . setElementStyle ( this . drawer , 'transform' , x ? 'translate3d(' + x + 'px,0,0)' : '' ) ;
833+ this . renderer . setElementStyle ( this . drawer , '-webkit-transform' ,
834+ x ? 'translate3d(' + x + 'px,0,0)' : '' ) ;
835+ }
836+ if ( opacity !== undefined ) {
837+ this . renderer . setElementStyle ( this . overlay , 'opacity' , opacity ) ;
838+ }
821839 }
822840
823841 private toggleOpenedEvent = ( evt ?) => {
0 commit comments