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 和动画了。

相关内容

热门资讯

透视系统!wepoker科技辅... 透视系统!wepoker科技辅助器,wepoker好友助力码(透视)黑科技教程(有挂介绍)wepok...
透视玄学!wepoker破解工... 透视玄学!wepoker破解工具,wejoker内置辅助(透视)安装教程(有挂技巧)亲,关键说明,w...
透视中牌率!wepoker软件... 透视中牌率!wepoker软件辅助程序,wepoker怎么获得好牌(透视)揭秘攻略(有挂工具)1、任...
透视代打!wepoker透视脚... 透视代打!wepoker透视脚本免费app,wepoker有没有挂(透视)力荐教程(有挂技巧)1、下...
透视好友!破解辅助插件wepo... 透视好友!破解辅助插件wepoker,wepoker黑侠破解(透视)高科技教程(有挂脚本);一、破解...
透视安装!wepoker永久免... 透视安装!wepoker永久免费脚本,wepoker钻石怎么看底牌(透视)高科技教程(有挂解说)1、...
透视好牌!wejoker辅助机... 透视好牌!wejoker辅助机器人,购买wepoker模拟器(透视)攻略教程(有挂规律);1、购买w...
透视ai!wejoker辅助软... 透视ai!wejoker辅助软件,wepoker透视脚本免费app(透视)2025新版总结(有挂解密...
透视中牌率!wepoker开脚... 透视中牌率!wepoker开脚本视频,wepoker有机器人吗(透视)扑克教程(有挂方法);1、金币...
透视美元局!wepoker究竟... 透视美元局!wepoker究竟有没有透视,wepoker怎么提高运气(透视)解密教程(有挂细节);1...