Angularng-content在动画中不起作用
创始人
2024-10-28 16:01:17
0

当我们在一个 Angular 组件的模板中使用 ng-content,并且想在其中添加动画时,有时会发现 ng-content 不起作用,导致动画无法正常展现。这是因为 ng-content 对动画造成了影响。

解决这个问题的方法是在 ng-content上添加一个 @ContentChildren 装饰器,以便在动画中使用它。示例如下:

import { Component, ContentChildren, QueryList } from '@angular/core';
import { trigger, transition, animate, style } from '@angular/animations';

@Component({
  selector: 'app-my-component',
  template: `
    
`, animations: [ trigger('myAnimation', [ transition(':enter', [ style({ opacity: 0 }), animate('1s', style({ opacity: 1 })) ]), transition(':leave', [ animate('1s', style({ opacity: 0 })) ]) ]) ] }) export class MyComponent { @ContentChildren('') myContent: QueryList; }

在上面的代码中,我们给 ng-content 添加了一个空的 @ContentChildren 装饰器,并在组件的模板上添加了动画。此时,我们就可以愉快的在组件中同时使用 ng-content 和动画了。

相关内容

热门资讯

第5分钟辅助!wepoker免... 第5分钟辅助!wepoker免费脚本咨询,aapoker能控制牌吗,方案教程(有挂秘诀)wepoke...
第1分钟辅助!aapoker ... 第1分钟辅助!aapoker ai插件,wepoker有什么规律,指引教程(有挂详情)1、进入游戏-...
第3分钟辅助!wepoker游... 第3分钟辅助!wepoker游戏安装教程,pokemmo辅助工具,经验教程(有挂教学)wepoker...
9分钟辅助!佛手在线大菠萝技巧... 9分钟辅助!佛手在线大菠萝技巧,hhpoker透视脚本视频,教程书教程(真的有挂)小薇(辅助器软件下...
第7分钟辅助!约局吧开挂,ha... 第7分钟辅助!约局吧开挂,hardrock透视工具,指南书教程(有挂详情)1、hardrock透视工...
第八分钟辅助!德扑圈有透视吗,... 第八分钟辅助!德扑圈有透视吗,hhpoker智能辅助插件,法门教程(有挂解密)1、完成hhpoker...
4分钟辅助!wepoker如何... 4分钟辅助!wepoker如何设置透视,wpk德州局透视,讲义教程(的确有挂)1、点击下载安装,we...
十分钟辅助!佛手在线有挂吗,w... 十分钟辅助!佛手在线有挂吗,wepoker辅助器如何使用,大纲教程(真的有挂)1、wepoker辅助...
2分钟辅助!wepoker怎么... 2分钟辅助!wepoker怎么开辅助,wepoker免费钻石,课程教程(有挂工具);1、打开软件启动...
六分钟辅助!wepoker安装... 六分钟辅助!wepoker安装教程,wepoker挂,大纲教程(揭秘有挂)1、下载好wepoker安...