-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(angular-ssr): do not use window and document on server side
- Loading branch information
Showing
6 changed files
with
45 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,21 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { Injectable, Inject, PLATFORM_ID } from '@angular/core'; | ||
import { isPlatformBrowser } from '@angular/common'; | ||
|
||
@Injectable() | ||
export class DomRefService { | ||
getNativeWindow(): any { | ||
return window; | ||
|
||
private fakeDocument: Document = <Document>{ body: {}, documentElement: {} }; | ||
private fakeWindow: Window = <Window>{ document: this.fakeDocument}; | ||
constructor( | ||
@Inject(PLATFORM_ID) private platformId: Object | ||
) { } | ||
getNativeWindow(): Window { | ||
if (isPlatformBrowser(this.platformId)) return window; | ||
else return this.fakeWindow; | ||
} | ||
|
||
getNativeDocument() { | ||
return document; | ||
if (isPlatformBrowser(this.platformId)) return document; | ||
else return this.fakeDocument; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters