Skip to content

Commit 040e0e3

Browse files
authored
fix(animations): provide fake document object in both AoT and JiT mode (#1164)
The fake document object that is needed for the angular animations should be provided both when using the static platform and the dynamic one. Can be tested with https://github.com/nativescript/ns-ng-animation-examples. ```bash // 1 git clone https://github.com/nativescript/ns-ng-animation-examples // 2 tns run android --bundle --env.aot // 3 // Navigate to the first example and expect the button to animate to opacity 0 when tapped. ``` fixes #1163
1 parent 8656753 commit 040e0e3

File tree

2 files changed

+8
-13
lines changed

2 files changed

+8
-13
lines changed

nativescript-angular/platform-common.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@ export class NativeScriptSanitizer extends Sanitizer {
6262
}
6363
}
6464

65+
// Add a fake polyfill for the document object
66+
(<any>global).document = (<any>global).document || {};
67+
const doc = (<any>global).document;
68+
doc.body = Object.assign((doc.body || {}), {
69+
isOverride: true,
70+
});
71+
6572
export class NativeScriptDocument {
6673
createElement(tag: string) {
6774
throw new Error("NativeScriptDocument is not DOM Document. There is no createElement() method.");
@@ -71,7 +78,7 @@ export class NativeScriptDocument {
7178
export const COMMON_PROVIDERS = [
7279
defaultPageFactoryProvider,
7380
{ provide: Sanitizer, useClass: NativeScriptSanitizer, deps: [] },
74-
{ provide: DOCUMENT, useClass: NativeScriptDocument, deps: [] },
81+
{ provide: DOCUMENT, useValue: doc },
7582
];
7683

7784
export class NativeScriptPlatformRef extends PlatformRef {

nativescript-angular/platform.ts

-12
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import {
1818
} from "@angular/platform-browser-dynamic";
1919

2020
import {
21-
DOCUMENT,
2221
ɵINTERNAL_BROWSER_PLATFORM_PROVIDERS as INTERNAL_BROWSER_PLATFORM_PROVIDERS
2322
} from "@angular/platform-browser";
2423

@@ -32,13 +31,6 @@ import {
3231
StaticProvider,
3332
} from "@angular/core";
3433

35-
// Add a fake polyfill for the document object
36-
(<any>global).document = (<any>global).document || {};
37-
const doc = (<any>global).document;
38-
doc.body = Object.assign((doc.body || {}), {
39-
isOverride: true,
40-
});
41-
4234
// Work around a TS bug requiring an imports of
4335
// InjectionToken, ViewEncapsulation and MissingTranslationStrategy
4436
// without using them
@@ -67,10 +59,6 @@ export const NS_COMPILER_PROVIDERS: StaticProvider[] = [
6759
},
6860
multi: true
6961
},
70-
{
71-
provide: DOCUMENT,
72-
useValue: doc,
73-
},
7462
];
7563

7664
// Dynamic platform

0 commit comments

Comments
 (0)