Skip to content

Instantly share code, notes, and snippets.

@thomaswmanion
Created May 24, 2019 22:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thomaswmanion/fac50de96cadbdb68f01cec91cd85a1c to your computer and use it in GitHub Desktop.
Save thomaswmanion/fac50de96cadbdb68f01cec91cd85a1c to your computer and use it in GitHub Desktop.
Enabling or Disabling Animations during Runtime in Angular
import { ɵNoopAnimationDriver, AnimationDriver, ɵWebAnimationsDriver } from '@angular/animations/browser';
export class AppAnimate implements AnimationDriver {
animationsDisabled = myVariableToDisableAnimations;
driver = this.animationsDisabled ? new ɵNoopAnimationDriver() : new ɵWebAnimationsDriver();
validateStyleProperty() {
return this.driver.validateStyleProperty.apply(this.driver, arguments);
}
matchesElement() {
return this.driver.matchesElement.apply(this.driver, arguments);
}
containsElement() {
return this.driver.containsElement.apply(this.driver, arguments);
}
query() {
return this.driver.query.apply(this.driver, arguments);
}
computeStyle() {
return this.driver.computeStyle.apply(this.driver, arguments);
}
animate() {
return this.driver.animate.apply(this.driver, arguments);
}
}
/**
* Then set the class as the provider for AnimationDriver in your AppModule with:
* { provide: AnimationDriver, useClass: AppAnimate }
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment