I'm creating an animation in angular, I need to know when it starts so I defined a callback. The thing is the callback is triggered when the component loads, even without changing the state.
Template
<button (click)="click()">click</button>
<div class="myclass" [@throwBall]="state" (@throwBall.start)="animStart($event)" >
</div>
The component:
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ],
animations: [
trigger('throwBall', [
state('steady', style({ })),
state('throw', style({ top: '300px' })),
transition('steady => throw', [animate('2s')])
]),
trigger('blockInitialRenderAnimation', [
transition(':enter', [])
])
]
})
export class AppComponent {
state = 'steady';
click() {
this.state = 'throw';
}
animStart(event: any) {
if (event.fromState !== 'void') {
console.log('anim start callback');
}
}
}
Here is a demo: https://stackblitz.com/edit/angular-9szgic
Why is the 'anim start callback' being displayed in the console when the component loads?