角度-如何仅添加一次全局动画触发器

问题描述 投票:0回答:1

我的大多数组件中都有相同的动画触发器。

是否有一种方法可以针对整个应用程序全局或特定功能模块仅一次导入一组触发器?

export const FADE_ANIMATION = [
    trigger('fade', [
        transition(':enter', [style({ opacity: 0 }), animate(200)]),
        transition(':leave', animate(200, style({ opacity: 0 }))),
    ]),
    trigger('fadeIn', [transition(':enter', [style({ opacity: 0 }), animate(200)])]),
    trigger('fadeInListItem', [transition(':enter', [style({ opacity: 0 }), animate(100)])]),
    trigger('fadeInList', [transition(':enter', [query('@fadeInListItem', stagger(50, animateChild()), { optional: true })])]),
];

@Component({
    selector: 'some-app-cmp',
    templateUrl: './some-app-cmp.component.html',
    styleUrls: ['./some-app-cmp.component.css'],
    animations: [...FADE_ANIMATION],
})

[官方docs只告诉您可以导入预定义的动画,就像我已经在做的。

angular angular-animations
1个回答
0
投票

我认为没有办法。我认为可以通过APP_BOOTSTRAP_LISTENER进行操作(因为它需要创建的每个组件),但到目前为止没有成功。

© www.soinside.com 2019 - 2024. All rights reserved.