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破解游戏盒子,hardrock作弊,科技教程(有挂攻略);最新版2024是一...
今日头条!德普辅助器辅助器怎么... 今日头条!德普辅助器辅助器怎么用,we poker游戏下,科技教程(有挂方法);人气非常高,ai更新...
玩家必看攻略!wepoker脚... 玩家必看攻略!wepoker脚本下载,hhpoker俱乐部是干嘛的,扑克教程(有挂教程)1、玩家可以...
推荐一款!hhpoker有作弊... 推荐一款!hhpoker有作弊的吗,wepoker透视版下载,揭秘攻略(有挂技巧);原来确实真的有挂...
最新通报!wepoker有透视... 最新通报!wepoker有透视吗,wejoker透视方法,揭秘教程(有挂神器);玩家必备必赢加哟《1...
新手必备!fishpoker透... 新手必备!fishpoker透视底牌,wepoker开辅助能查到吗,普及教程(有挂神器)这是由厦门游...
交流学习经验!德扑圈有透视吗,... 1、交流学习经验!德扑圈有透视吗,hhpoker万能辅助器,德州教程(有挂技巧);详细教程。2、hh...
程序员教你!pokermast... 1、程序员教你!pokermaster脚本,大菠萝辅助器,教你攻略(有挂技巧)。2、大菠萝辅助器透视...
必备攻略!wepoker有辅助... 必备攻略!wepoker有辅助吗,德普之星app安卓版破解版,详细教程(有挂教程)1、许多玩家不知道...
实测交流!黑侠破解wepoke... 实测交流!黑侠破解wepoker,wepoker俱乐部辅助器,力荐教程(有挂软件)1、玩家可以在we...