From ee13f41534e3b1511609030eff36636e79a6c1b1 Mon Sep 17 00:00:00 2001 From: crisbeto Date: Tue, 20 Jun 2017 07:42:34 +0200 Subject: [PATCH] fix(directionality): error on platform-server Fixes null pointer error in the directionality service on `platform-server`. Fixes #5233. --- src/lib/core/bidi/directionality.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/lib/core/bidi/directionality.ts b/src/lib/core/bidi/directionality.ts index 5ec89de17a11..443a177141b6 100644 --- a/src/lib/core/bidi/directionality.ts +++ b/src/lib/core/bidi/directionality.ts @@ -41,13 +41,14 @@ export class Directionality { change = new EventEmitter(); constructor(@Optional() @Inject(DIR_DOCUMENT) _document?: any) { - if (typeof _document === 'object' && !!_document) { + const parent = _document ? (_document.body || _document.documentElement) : null; + + if (parent) { // TODO: handle 'auto' value - // We still need to account for dir="auto". // It looks like HTMLElemenet.dir is also "auto" when that's set to the attribute, // but getComputedStyle return either "ltr" or "rtl". avoiding getComputedStyle for now - // though, we're already calling it for the theming check. - this.value = (_document.body.dir || _document.documentElement.dir || 'ltr') as Direction; + this.value = (parent.dir || 'ltr') as Direction; } } }