简体   繁体   English

Angular 4 - 如何从Directive中运行动画?

[英]Angular 4 - How to run animation from within Directive?

I have a pending issue on the repo here , but I figured it would be useful to ask it here anyway. 我在这里有一个悬而未决的回购问题 ,但我认为无论如何都要在这里提问。

I want to trigger an animation from within a Directive programmatically. 我想以编程方式从指令中触发动画。 When using Renderer.animate , I get: 使用Renderer.animate ,我得到:

Renderer.animate is no longer supported!

When using Renderer.invokeElementMethod , I get: 使用Renderer.invokeElementMethod ,我得到:

Cannot read property 'apply' of undefined

How would I do this? 我该怎么做?

Changes are coming to Angular! 变化即将来临Angular! See this GitHub issue in the official Angular repo. 在官方Angular回购中查看此GitHub问题

TL;DR TL; DR

What's really good: With the first beta of angular 4.1 (which comes out as the follow-up release to this weeks 4.0.0) you can do the following: 什么是非常好的:使用角度4.1的第一个测试版(作为本周4.0.0的后续版本发布),您可以执行以下操作:

class MyCmp {


constructor(private _builder: AnimationBuilder) {
   }
   myMethod() {
      const animation = this._builder.build([
        style(...),
        animate(...),
        group([
          animate(...)
          animate(...)
          animate(...)
        ])
      ]);
      const player = animation.create(someElement);
      player.play();
   }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM