An example of Angular 2 animation ended callback function

后端 未结 2 542
傲寒
傲寒 2021-01-01 19:14

I am trying to create a function that will be triggered at the end of an animation in Angular 2 (I am using the latest angular cli).

I have been on the Angular Anima

2条回答
  •  抹茶落季
    2021-01-01 19:31

    This is working example:

    import {Component, NgModule, Input, trigger, state, animate, transition, style, HostListener } from '@angular/core'
    import {BrowserModule} from '@angular/platform-browser'
    
    @Component({
      selector : 'toggle',
      animations: [
        trigger('toggle', [
          state('true', style({ opacity: 1; color: 'red' })),
          state('void', style({ opacity: 0; color: 'blue' })),
          transition(':enter', animate('500ms ease-in-out')),
          transition(':leave', animate('500ms ease-in-out'))
        ])
      ],
      template: `
      
    ` }) export class Toggle { @Input() show:boolean = true; @HostListener('document:click') onClick(){ this.show=!this.show; } animationStarted($event) { console.log('Start'); } animationDone($event) { console.log('End'); } } @Component({ selector: 'my-app', template: `
    Hey!
    `, }) export class App { } @NgModule({ imports: [ BrowserModule ], declarations: [ App, Toggle ], bootstrap: [ App ] }) export class AppModule {}

    Plunker

提交回复
热议问题