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

相关内容

热门资讯

透视插件!德扑HHpoker有... 透视插件!德扑HHpoker有挂吗(透视)开挂辅助软件(总是是有挂)-哔哩哔哩暗藏猫腻,小编详细说明...
透视黑科技!菠萝辅助器免费版的... 透视黑科技!菠萝辅助器免费版的特点,hhpoker透视脚本,教材教程(好像存在有挂)-哔哩哔哩1、全...
透视开挂!哈糖大菠萝可以开挂吗... 透视开挂!哈糖大菠萝可以开挂吗(透视)开挂辅助脚本(原来是真的挂)-哔哩哔哩透视开挂!哈糖大菠萝可以...
透视计算!sohoopoker... 透视计算!sohoopoker辅助,hhpoker辅助码,操作教程(原来是真的挂)-哔哩哔哩1、打开...
透视漏洞!wpk透视工作室(透... 透视漏洞!wpk透视工作室(透视)开挂辅助神器(好像是有挂)-哔哩哔哩wpk透视工作室是一种具有地方...
透视有挂!wepoker俱乐部... 透视有挂!wepoker俱乐部辅助,wepoker私局辅助,方式教程(原来有挂)-哔哩哔哩1、在we...
透视ios!哈糖大菠萝可以开挂... 透视ios!哈糖大菠萝可以开挂吗(透视)开挂辅助攻略(竟然真的有挂)-哔哩哔哩1)哈糖大菠萝可以开挂...
透视工具!xpoker辅助,w... 透视工具!xpoker辅助,wepoker免费脚本,烘培教程(总是是有挂)-哔哩哔哩一、wepoke...
透视技巧!pokerrrr2辅... 透视技巧!pokerrrr2辅助(透视)开挂辅助攻略(都是真的是有挂)-哔哩哔哩1、pokerrrr...
透视app!wepoker辅助... 透视app!wepoker辅助软件价格,wepoker辅助器如何使用,烘培教程(其实有挂)-哔哩哔哩...