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() {
    // 销毁组件
  }

}

相关内容

热门资讯

四分钟辅助!wpk辅助,epo... 四分钟辅助!wpk辅助,epoker透视,机巧教程(有挂方式)1、下载好epoker透视透视辅助下载...
1分钟辅助!红龙poker辅助... 1分钟辅助!红龙poker辅助器免费观看,微扑克微乐辅助,诀窍教程(今日头条)1、在红龙poker辅...
9分钟辅助!佛手在线大菠萝智能... 9分钟辅助!佛手在线大菠萝智能辅助器,wpk有那种辅助吗,积累教程(确实有挂)1、佛手在线大菠萝智能...
4分钟辅助!hhpoker视频... 4分钟辅助!hhpoker视频巡查真的假的,aa poker辅助包,步骤教程(有挂技巧)hhpoke...
六分钟辅助!约局吧德州可以透视... 六分钟辅助!约局吧德州可以透视吗,拱趴游戏破解器,技法教程(有挂实锤)1、每一步都需要思考,不同水平...
第5分钟辅助!pokemmo内... 第5分钟辅助!pokemmo内置修改器,werplan外卦神器,方针教程(有挂详细)1)pokemm...
九分钟辅助!wepoker高级... 九分钟辅助!wepoker高级辅助,hh poker软件,机巧教程(有人有挂)1、下载好wepoke...
第十分钟辅助!wepoker透... 第十分钟辅助!wepoker透视脚本免费下载,约局吧作弊脚本,操作教程(有挂秘籍)1、全新机制【we...
4分钟辅助!wepoker透视... 4分钟辅助!wepoker透视脚本免费,pokemmo手机脚本,讲义教程(揭秘有挂)wepoker透...
第九分钟辅助!newpoker... 第九分钟辅助!newpoker怎么安装脚本,pokemmo手机辅助软件,方案教程(有挂技巧)1、该软...