6
6
* found in the LICENSE file at https://angular.io/license
7
7
*/
8
8
9
- import { Injectable } from '@angular/core' ;
9
+ import { Inject , Injectable , PLATFORM_ID } from '@angular/core' ;
10
+ import { isPlatformBrowser } from '@angular/common' ;
10
11
11
12
12
13
// Whether the current platform supports the V8 Break Iterator. The V8 check
@@ -20,7 +21,7 @@ const hasV8BreakIterator = (typeof Intl !== 'undefined' && (Intl as any).v8Break
20
21
@Injectable ( { providedIn : 'root' } )
21
22
export class Platform {
22
23
/** Whether the Angular application is being rendered in the browser. */
23
- isBrowser : boolean = typeof document === 'object' && ! ! document ;
24
+ isBrowser : boolean = isPlatformBrowser ( this . _platformId ) ;
24
25
25
26
/** Whether the current browser is Microsoft Edge. */
26
27
EDGE : boolean = this . isBrowser && / ( e d g e ) / i. test ( navigator . userAgent ) ;
@@ -37,11 +38,11 @@ export class Platform {
37
38
// Webkit is part of the userAgent in EdgeHTML, Blink and Trident. Therefore we need to
38
39
// ensure that Webkit runs standalone and is not used as another engine's base.
39
40
WEBKIT : boolean = this . isBrowser &&
40
- / A p p l e W e b K i t / i. test ( navigator . userAgent ) && ! this . BLINK && ! this . EDGE && ! this . TRIDENT ;
41
+ / A p p l e W e b K i t / i. test ( navigator . userAgent ) && ! this . BLINK && ! this . EDGE && ! this . TRIDENT ;
41
42
42
43
/** Whether the current platform is Apple iOS. */
43
44
IOS : boolean = this . isBrowser && / i P a d | i P h o n e | i P o d / . test ( navigator . userAgent ) &&
44
- ! ( window as any ) . MSStream ;
45
+ ! ( window as any ) . MSStream ;
45
46
46
47
/** Whether the current browser is Firefox. */
47
48
// It's difficult to detect the plain Gecko engine, because most of the browsers identify
@@ -51,12 +52,16 @@ export class Platform {
51
52
FIREFOX : boolean = this . isBrowser && / ( f i r e f o x | m i n e f i e l d ) / i. test ( navigator . userAgent ) ;
52
53
53
54
/** Whether the current platform is Android. */
54
- // Trident on mobile adds the android platform to the userAgent to trick detections.
55
+ // Trident on mobile adds the android platform to the userAgent to trick detections.
55
56
ANDROID : boolean = this . isBrowser && / a n d r o i d / i. test ( navigator . userAgent ) && ! this . TRIDENT ;
56
57
57
58
/** Whether the current browser is Safari. */
58
59
// Safari browsers will include the Safari keyword in their userAgent. Some browsers may fake
59
60
// this and just place the Safari keyword in the userAgent. To be more safe about Safari every
60
61
// Safari browser should also use Webkit as its layout engine.
61
62
SAFARI : boolean = this . isBrowser && / s a f a r i / i. test ( navigator . userAgent ) && this . WEBKIT ;
63
+
64
+ constructor ( @Inject ( PLATFORM_ID ) private _platformId : Object ) {
65
+ }
62
66
}
67
+
0 commit comments