-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): improve
WindowService
to work on both browser and server
- Loading branch information
Showing
2 changed files
with
11 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,16 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { DOCUMENT } from '@angular/common'; | ||
import { Inject, Injectable } from '@angular/core'; | ||
|
||
/** | ||
* Service to interact with the window object. | ||
* Service to interact with the `window` object (or its equivalent on a server platform). | ||
*/ | ||
@Injectable() | ||
export class WindowService { | ||
|
||
constructor(@Inject(DOCUMENT) private _doc: Document) {} | ||
|
||
get nativeWindow(): any { | ||
return _window(); | ||
return this._doc?.defaultView || window; | ||
} | ||
} | ||
|
||
function _window(): any { | ||
// Return the global native browser window object | ||
return typeof window !== 'undefined' ? window : undefined; | ||
} |