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

相关内容

热门资讯

目前!poker辅助器免费安装... 目前!poker辅助器免费安装,德州局透视脚本,模板教程(今日头条)-哔哩哔哩1、让任何用户在无需p...
记者获悉!wpk辅助购买(透视... 记者获悉!wpk辅助购买(透视)一直是有挂(有挂解惑开挂辅助安装)-哔哩哔哩一、wpk辅助购买软件透...
目前!aapoker俱乐部靠谱... 目前!aapoker俱乐部靠谱吗,wepoker轻量版有透视吗,机巧教程(有挂解密)-哔哩哔哩一、w...
此事引发网友热议!来玩德州破解... 此事引发网友热议!来玩德州破解器(透视)原来真的有挂(确实有挂开挂辅助工具)-哔哩哔哩1、此事引发网...
据权威媒体报道!cloudpo... 据权威媒体报道!cloudpoker辅助,扑克之星辅助,学习教程(有挂详情)-哔哩哔哩1)扑克之星辅...
迎来新发展!pokemmo脚本... 迎来新发展!pokemmo脚本辅助器(透视)一贯是有挂(有挂教学开挂辅助插件)-哔哩哔哩1)poke...
此事引发网友热议!aapoke... 此事引发网友热议!aapoker透视脚本,wepoker辅助脚本,烘培教程(有挂秘籍)-哔哩哔哩1、...
为切实保障!wepoker好友... 为切实保障!wepoker好友房开挂(透视)原来有挂(有挂透明挂开挂辅助安装)-哔哩哔哩1、实时we...
无独有偶!hhpoker是真的... 无独有偶!hhpoker是真的假的,wpk辅助器,法子教程(有挂攻略)-哔哩哔哩一、hhpoker是...
出现新变化!wepoker究竟... 出现新变化!wepoker究竟有没有透视(透视)果然有挂(真实有挂开挂辅助辅助器)-哔哩哔哩1、we...