如何使用angular中单独的.ts文件中的动画触发器?

k7fdbhmy  于 2021-09-13  发布在  Java
关注(0)|答案(1)|浏览(288)

以下是以Angular 导出动画触发器的示例:

import { animation, style, animate, trigger, transition, useAnimation } from '@angular/animations';
export const triggerAnimation = trigger('openClose', [
  transition('open => closed', [
    useAnimation(transitionAnimation, {
      params: {
        height: 0,
        opacity: 1,
        backgroundColor: 'red',
        time: '1s'
      }
    })
  ])
]);

但我不知道如何在我的组件中使用它。有useanimation()方法,但没有像usetrigger()之类的方法。
如何使用angular中单独的.ts文件中的动画触发器?

xienkqul

xienkqul1#

与使用任何其他动画的方式相同,如官方指南中所列。基本上,您可以将动画添加到 @Component 唯一的区别是您必须导入在不同模块中定义的模块,例如。

import { triggerAnimation } from 'path-to-your-file-with-animations'

    @Component({
      selector: 'app-root',
      templateUrl: 'app.component.html',
      styleUrls: ['app.component.css'],
      animations: [
        triggerAnimation
      ]
    })

相关问题