Created
May 24, 2019 22:07
-
-
Save thomaswmanion/fac50de96cadbdb68f01cec91cd85a1c to your computer and use it in GitHub Desktop.
Enabling or Disabling Animations during Runtime in Angular
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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