It may be an elegant solution, but it works like angular 4.0.0: (Disclaimer I found the basis for this code for 2.0)
Add the following imports to your app.module:
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { AnimationDriver, ɵWebAnimationsDriver } from '@angular/animations/browser';
Add this function:
export function animationFactory(): any {
const noop = AnimationDriver.NOOP;
const driver = new ɵWebAnimationsDriver();
return {
animate: (element: any, keyframes: {
[key: string]: string | number;
}[], duration: number, delay: number, easing: string, previousPlayers?: any[]) => {
if (!wantToAnimate) {
return noop.animate(element, keyframes, duration, delay, easing, previousPlayers);
} else {
return driver.animate(element, keyframes, duration, delay, easing, previousPlayers);
}
}
};
};
import BrowserAnimationModule
imports: [
...,
BrowserAnimationsModule,
]
provide AnimationDriver using the factory function above
providers: [
...,
{ provide: AnimationDriver, useFactory: animationFactory },
]
source
share