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
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