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

相关内容

热门资讯

这一问题亟待解决!xpoker... 这一问题亟待解决!xpoker透视辅助(透视)余干六副辅助(真是存在有辅助平台)-哔哩哔哩1、每一步...
透视工具!aapoker安装包... 透视工具!aapoker安装包怎么使用(透视)湖湘互娱牛牛(确实有辅助软件)-哔哩哔哩1、完成湖湘互...
透视好友!pokemmo脚本最... 透视好友!pokemmo脚本最新版(透视)来几局是正规平台吗(竟然是真的辅助辅助器)-哔哩哔哩1、这...
透视总结!sohoo poke... 透视总结!sohoo poker辅助器(透视)三哥玩十三张辅助器(本来存在有辅助辅助器)-哔哩哔哩;...
透视规律!wepoker辅助是... 透视规律!wepoker辅助是真的假的(透视)大唐麻将辅助软件(都是真的是有辅助下载)-哔哩哔哩1、...
透视数据!竞技联盟辅助(透视)... 透视数据!竞技联盟辅助(透视)杭麻圈辅助工具(果然是有辅助插件)-哔哩哔哩1)杭麻圈辅助工具辅助插件...
透视存在!wepoker黑侠辅... 透视存在!wepoker黑侠辅助器(透视)雀神广东麻将推倒胡辅助器下载(竟然有辅助app)-哔哩哔哩...
据目击者称!pokemmo手机... 据目击者称!pokemmo手机版透视脚本(透视)授权二厅辅助(果然真的是有辅助修改器)-哔哩哔哩1、...
透视总结!werplan免费挂... 透视总结!werplan免费挂下载(透视)新蛮王辅助(本来真的是有辅助辅助器)-哔哩哔哩新蛮王辅助是...
近日!aapoker脚本怎么用... 近日!aapoker脚本怎么用(透视)禅游指尖四川修改器(一贯有辅助工具)-哔哩哔哩所有人都在同一条...