Skip to content

Commit

Permalink
fix(directionality): error on platform-server
Browse files Browse the repository at this point in the history
Fixes null pointer error in the directionality service on `platform-server`.

Fixes angular#5233.
  • Loading branch information
crisbeto committed Jun 20, 2017
1 parent a2a25be commit ee13f41
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/lib/core/bidi/directionality.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,14 @@ export class Directionality {
change = new EventEmitter<void>();

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;
}
}
}
Expand Down

0 comments on commit ee13f41

Please sign in to comment.