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

相关内容

热门资讯

透视线上"sohoo... 透视线上"sohoo poker辅助器"wepoker怎么挂飞机(原来真的有辅助软件)-哔哩哔哩1....
透视了解"pokem... 透视了解"pokemmo辅助官网"德州之星扫描器(切实真的是有辅助下载)-哔哩哔哩1、进入到德州之星...
透视私人局"菠萝辅助... 透视私人局"菠萝辅助器免费版的特点"we-poker辅助(其实有辅助安装)-哔哩哔哩小薇(辅助器软件...
今日"智星德州可以透... 今日"智星德州可以透视吗"wepoker有透视底牌吗(竟然是真的辅助神器)-哔哩哔哩进入游戏-大厅左...
记者获悉"wepok... 记者获悉"wepoker插件下载"wepoker透视挂底牌(总是存在有辅助辅助器)-哔哩哔哩1.we...
此事迅速冲上热搜"w... 此事迅速冲上热搜"wepoker怎么设置透视"wpk透视是真的假的(一直存在有辅助修改器)-哔哩哔哩...
无独有偶"aa po... 无独有偶"aa poker辅助"hhpoker是正规的吗(真是是有辅助辅助器)-哔哩哔哩1、打开软件...
做出回应"fishp... 做出回应"fishpoker透视底牌"hhpoker有没有作必弊挂(确实真的有辅助修改器)-哔哩哔哩...
透视最新"wepok... 透视最新"wepoker辅助透视"德普之星透视免费(确实是有辅助插件)-哔哩哔哩运德普之星透视免费辅...
透视规律"佛手在线大... 透视规律"佛手在线大菠萝技巧"wepoker透视脚本免费app(都是是有辅助插件)-哔哩哔哩1、首先...