Skip to content

Commit

Permalink
fix(animations): resolve error when using AnimationBuilder with platf…
Browse files Browse the repository at this point in the history
…orm-server (#18642)

Use an injected DOCUMENT instead of assuming the global 'document'
exists.

Fixes #18635.

PR Close #18642
  • Loading branch information
vikerman authored and mhevery committed Aug 17, 2017
1 parent e8b98a7 commit 5dd1744
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
7 changes: 4 additions & 3 deletions packages/platform-browser/animations/src/animation_builder.ts
Expand Up @@ -6,7 +6,8 @@
* found in the LICENSE file at https://angular.io/license
*/
import {AnimationBuilder, AnimationFactory, AnimationMetadata, AnimationOptions, AnimationPlayer, NoopAnimationPlayer, sequence} from '@angular/animations';
import {Injectable, RendererFactory2, RendererType2, ViewEncapsulation} from '@angular/core';
import {Inject, Injectable, RendererFactory2, RendererType2, ViewEncapsulation} from '@angular/core';
import {DOCUMENT} from '@angular/platform-browser';

import {AnimationRenderer} from './animation_renderer';

Expand All @@ -15,15 +16,15 @@ export class BrowserAnimationBuilder extends AnimationBuilder {
private _nextAnimationId = 0;
private _renderer: AnimationRenderer;

constructor(rootRenderer: RendererFactory2) {
constructor(rootRenderer: RendererFactory2, @Inject(DOCUMENT) doc: any) {
super();
const typeData = {
id: '0',
encapsulation: ViewEncapsulation.None,
styles: [],
data: {animation: []}
} as RendererType2;
this._renderer = rootRenderer.createRenderer(document.body, typeData) as AnimationRenderer;
this._renderer = rootRenderer.createRenderer(doc.body, typeData) as AnimationRenderer;
}

build(animation: AnimationMetadata|AnimationMetadata[]): AnimationFactory {
Expand Down
4 changes: 3 additions & 1 deletion packages/platform-server/test/integration_spec.ts
Expand Up @@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/

import {animate, style, transition, trigger} from '@angular/animations';
import {AnimationBuilder, animate, style, transition, trigger} from '@angular/animations';
import {APP_BASE_HREF, PlatformLocation, isPlatformServer} from '@angular/common';
import {ApplicationRef, CompilerFactory, Component, HostListener, Input, NgModule, NgModuleRef, NgZone, PLATFORM_ID, PlatformRef, ViewEncapsulation, destroyPlatform, getPlatform} from '@angular/core';
import {TestBed, async, inject} from '@angular/core/testing';
Expand Down Expand Up @@ -98,6 +98,8 @@ class SVGServerModule {
[transition('void => *', [style({'opacity': '0'}), animate(500, style({'opacity': '1'}))])])],
})
class MyAnimationApp {
constructor(private builder: AnimationBuilder) {}

text = 'Works!';
}

Expand Down

0 comments on commit 5dd1744

Please sign in to comment.