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

相关内容

热门资讯

科普透视!模拟器打开hhpok... 科普透视!模拟器打开hhpoker,hhpoker软件可以玩吗,模块教程(有挂工具)-哔哩哔哩科普透...
关于透视!wepoker安装教... 关于透视!wepoker安装教程!确实真的是有辅助插件(果真有挂)-哔哩哔哩1、完成wepoker安...
教你透视!wepoker有透视... 教你透视!wepoker有透视功能吗,HH平台挂,要领教程(有挂秘诀)-哔哩哔哩1、上手简单,内置详...
解迷透视!大菠萝免费辅助!原来... 解迷透视!大菠萝免费辅助!原来是真的有辅助攻略(存在有挂)-哔哩哔哩1、进入游戏-大厅左侧-新手福利...
普及透视!德普之星透视辅助软件... 普及透视!德普之星透视辅助软件激活码,德州机器人代打脚本,模块教程(有挂教学)-哔哩哔哩德普之星透视...
关于透视!pokemmo免费脚... 关于透视!pokemmo免费脚本!其实有辅助插件(有挂细节)-哔哩哔哩1.pokemmo免费脚本 选...
必备透视!wepoker国外版... 必备透视!wepoker国外版透视,德州机器人代打脚本,攻略教程(有挂方法)-哔哩哔哩1、完成德州机...
有挂透视!德州局怎么透视!都是... 有挂透视!德州局怎么透视!都是是有辅助软件(有挂方法)-哔哩哔哩1、点击下载安装,德州局怎么透视脚本...
详细透视!黑侠破解wepoke... 详细透视!黑侠破解wepoker,wepoker辅助器软件下载,模板教程(有挂透视)-哔哩哔哩1、该...
教你透视!sohoopoker... 教你透视!sohoopoker辅助!好像存在有辅助攻略(有挂神器)-哔哩哔哩1、进入到sohoopo...