Skip to content
This repository has been archived by the owner on Nov 6, 2024. It is now read-only.

Commit

Permalink
Makes MzMediaService compatible with angular universal (#338)
Browse files Browse the repository at this point in the history
  • Loading branch information
christophstach authored and jfcere committed Aug 6, 2018
1 parent 2c45e94 commit 301f50e
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/src/media/media.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Injectable } from '@angular/core';
import { isPlatformBrowser } from '@angular/common';
import { Inject, Injectable, PLATFORM_ID } from '@angular/core';
import { fromEvent, Observable } from 'rxjs';
import { map, publishReplay, refCount, startWith } from 'rxjs/operators';

Expand Down Expand Up @@ -32,8 +33,12 @@ export class MzMediaService {
},
];

constructor() {
this.media = this.registerWindowResizeListener();
constructor(@Inject(PLATFORM_ID) platformId: Object) {
if (isPlatformBrowser(platformId)) {
this.media = this.registerWindowResizeListener();
} else {
this.media = Observable.create();
}
}

isActive(breakpoint: string): Observable<boolean> {
Expand Down

0 comments on commit 301f50e

Please sign in to comment.