Angular动画不允许组件在应该销毁时被销毁。
创始人
2024-10-24 13:01:34
0

添加一个结束回调函数,在完成动画后销毁组件。

示例代码:

在组件的HTML模板中添加动画:

// 组件内容

在组件的TS文件中,定义动画和结束回调函数:

import { Component, OnInit } from '@angular/core';
import { trigger, transition, style, animate } from '@angular/animations';

@Component({
  selector: 'app-my-component',
  templateUrl: './my-component.component.html',
  styleUrls: ['./my-component.component.css'],
  animations: [
    trigger('fade', [
      transition(':leave', [
        animate(300, style({opacity: 0}))
      ])
    ])
  ]
})
export class MyComponentComponent implements OnInit {

  state: string = 'active';

  constructor() { }

  ngOnInit(): void {
  }

  onAnimationDone(event: any) {
    if (event.toState === 'void') {
      // 动画完成后,销毁组件
      this.destroyComponent();
    }
  }

  destroyComponent() {
    // 销毁组件
  }

}

相关内容

热门资讯

总结透视!拱趴大菠萝万能挂!原... 总结透视!拱趴大菠萝万能挂!原来一直都是有辅助神器(有挂助手)-哔哩哔哩1、拱趴大菠萝万能挂免费脚本...
揭露透视!wepoker怎么提... 揭露透视!wepoker怎么提高运气,aapoker透视脚本下载,手段教程(有挂攻略)-哔哩哔哩所有...
解谜透视!hardrock作必... 解谜透视!hardrock作必弊!好像是真的有辅助教程(证实有挂)-哔哩哔哩1、超多福利:超高返利,...
详细透视!agpoker辅助,... 详细透视!agpoker辅助,hhpoker透视工具,步骤教程(有挂讲解)-哔哩哔哩hhpoker透...
普及透视!hardrock作必... 普及透视!hardrock作必弊!切实一直总是有辅助app(竟然有挂)-哔哩哔哩暗藏猫腻,小编详细说...
揭幕透视!红龙poker有辅助... 揭幕透视!红龙poker有辅助吗,哈糖大菠萝有挂吗,练习教程(真的有挂)-哔哩哔哩揭幕透视!红龙po...
详细透视!pokemmo修改器... 详细透视!pokemmo修改器手机版!一直真的是有辅助工具(有挂方法)-哔哩哔哩1、许多玩家不知道p...
总结透视!hhpoker是内部... 总结透视!hhpoker是内部控制吗,aapoker怎么开辅助器,操作教程(有挂功能)-哔哩哔哩hh...
教你透视!pokemmo辅助器... 教你透视!pokemmo辅助器手机版下载!一直是有辅助软件(详细教程)-哔哩哔哩1、每一步都需要思考...
辅助透视!sohoo辅助,po... 辅助透视!sohoo辅助,pokemmo脚本辅助下载,项目教程(有挂详细)-哔哩哔哩1、实时poke...