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永久免费脚本,一贯真的是有挂(透视)解说技巧(有挂工具)1、每一步都需要思考...
透视线上!wepoker透视a... 透视线上!wepoker透视app下载,都是是有挂(透视)新2025版(有挂工具);暗藏猫腻,小编详...
辅助透视!wepoker破解版... 辅助透视!wepoker破解版内购,原生有挂(透视)2025新版(有挂工具)1、首先打开wepoke...
透视脚本!hhpoker辅助软... 透视脚本!hhpoker辅助软件,都是有挂(透视)透视教程(有挂工具)暗藏猫腻,小编详细说明hhpo...
透视最新!红龙poker有辅助... 透视最新!红龙poker有辅助吗,往昔真的是有挂(透视)线上教程(有挂揭秘)红龙poker有辅助吗辅...
透视最新!wepoker钻石怎... 透视最新!wepoker钻石怎么看底牌,从来有挂(透视)辅助教程(有挂攻略);1、在wepoker钻...
透视模拟器!wepoker看底... 透视模拟器!wepoker看底牌,其实存在有挂(透视)揭秘教程(有挂细节)1.wepoker看底牌 ...
透视教程!pokemmo辅助器... 透视教程!pokemmo辅助器手机版下载,本来真的有挂(透视)详细教程(有挂细节)1、点击下载安装,...
透视私人局!约局吧辅助器,素来... 透视私人局!约局吧辅助器,素来是真的有挂(透视)解说技巧(有挂详情);运约局吧辅助器辅助工具,进入游...
透视私人局!wepoker辅助... 透视私人局!wepoker辅助器,一贯是有挂(透视)力荐教程(有挂黑科技)1、进入游戏-大厅左侧-新...