fix(animations): resolve error when using AnimationBuilder with platform-server (#18642)
Use an injected DOCUMENT instead of assuming the global 'document' exists. Fixes #18635. PR Close #18642
This commit is contained in:
parent
21c44672c4
commit
845c68fdb3
|
@ -6,7 +6,8 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
import {AnimationBuilder, AnimationFactory, AnimationMetadata, AnimationOptions, AnimationPlayer, NoopAnimationPlayer, sequence} from '@angular/animations';
|
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';
|
import {AnimationRenderer} from './animation_renderer';
|
||||||
|
|
||||||
|
@ -15,7 +16,7 @@ export class BrowserAnimationBuilder extends AnimationBuilder {
|
||||||
private _nextAnimationId = 0;
|
private _nextAnimationId = 0;
|
||||||
private _renderer: AnimationRenderer;
|
private _renderer: AnimationRenderer;
|
||||||
|
|
||||||
constructor(rootRenderer: RendererFactory2) {
|
constructor(rootRenderer: RendererFactory2, @Inject(DOCUMENT) doc: any) {
|
||||||
super();
|
super();
|
||||||
const typeData = {
|
const typeData = {
|
||||||
id: '0',
|
id: '0',
|
||||||
|
@ -23,7 +24,7 @@ export class BrowserAnimationBuilder extends AnimationBuilder {
|
||||||
styles: [],
|
styles: [],
|
||||||
data: {animation: []}
|
data: {animation: []}
|
||||||
} as RendererType2;
|
} 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 {
|
build(animation: AnimationMetadata|AnimationMetadata[]): AnimationFactory {
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* 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 {APP_BASE_HREF, PlatformLocation, isPlatformServer} from '@angular/common';
|
||||||
import {HttpClient, HttpClientModule} from '@angular/common/http';
|
import {HttpClient, HttpClientModule} from '@angular/common/http';
|
||||||
import {HttpClientTestingModule, HttpTestingController} from '@angular/common/http/testing';
|
import {HttpClientTestingModule, HttpTestingController} from '@angular/common/http/testing';
|
||||||
|
@ -100,6 +100,8 @@ class SVGServerModule {
|
||||||
[transition('void => *', [style({'opacity': '0'}), animate(500, style({'opacity': '1'}))])])],
|
[transition('void => *', [style({'opacity': '0'}), animate(500, style({'opacity': '1'}))])])],
|
||||||
})
|
})
|
||||||
class MyAnimationApp {
|
class MyAnimationApp {
|
||||||
|
constructor(private builder: AnimationBuilder) {}
|
||||||
|
|
||||||
text = 'Works!';
|
text = 'Works!';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue