diff --git a/nativescript-angular/platform-common.ts b/nativescript-angular/platform-common.ts index a5679a0b4..30f7d6f66 100644 --- a/nativescript-angular/platform-common.ts +++ b/nativescript-angular/platform-common.ts @@ -62,6 +62,13 @@ export class NativeScriptSanitizer extends Sanitizer { } } +// Add a fake polyfill for the document object +(global).document = (global).document || {}; +const doc = (global).document; +doc.body = Object.assign((doc.body || {}), { + isOverride: true, +}); + export class NativeScriptDocument { createElement(tag: string) { throw new Error("NativeScriptDocument is not DOM Document. There is no createElement() method."); @@ -71,7 +78,7 @@ export class NativeScriptDocument { export const COMMON_PROVIDERS = [ defaultPageFactoryProvider, { provide: Sanitizer, useClass: NativeScriptSanitizer, deps: [] }, - { provide: DOCUMENT, useClass: NativeScriptDocument, deps: [] }, + { provide: DOCUMENT, useValue: doc }, ]; export class NativeScriptPlatformRef extends PlatformRef { diff --git a/nativescript-angular/platform.ts b/nativescript-angular/platform.ts index ee7c30606..eb9666917 100644 --- a/nativescript-angular/platform.ts +++ b/nativescript-angular/platform.ts @@ -18,7 +18,6 @@ import { } from "@angular/platform-browser-dynamic"; import { - DOCUMENT, ɵINTERNAL_BROWSER_PLATFORM_PROVIDERS as INTERNAL_BROWSER_PLATFORM_PROVIDERS } from "@angular/platform-browser"; @@ -32,13 +31,6 @@ import { StaticProvider, } from "@angular/core"; -// Add a fake polyfill for the document object -(global).document = (global).document || {}; -const doc = (global).document; -doc.body = Object.assign((doc.body || {}), { - isOverride: true, -}); - // Work around a TS bug requiring an imports of // InjectionToken, ViewEncapsulation and MissingTranslationStrategy // without using them @@ -67,10 +59,6 @@ export const NS_COMPILER_PROVIDERS: StaticProvider[] = [ }, multi: true }, - { - provide: DOCUMENT, - useValue: doc, - }, ]; // Dynamic platform