Animations in the host element should be handled something like this:
animations: [
trigger('toggleDrawer', [
state('closed', style({
transform: 'translateX(0)'
})),
state('opened', style({
transform: 'translateX(80vw)'
})),
transition('closed <=> opened', animate(300))
])
]
And HostBinding / HostListener
private state: 'opened' | 'closed' = 'closed';
// binds the animation to the host component
@HostBinding('@toggleDrawer') get getToggleDrawer(): string {
return this.state === 'closed' ? 'opened' : 'closed';
}
@HostListener('@toggleDrawer.start', ['$event']) startDrawerHandler(event: any): void {
console.log(event);
}
@HostListener('@toggleDrawer.done', ['$event']) doneDrawerHandler(event: any): void {
console.log(event);
}
Keeping in mind that the HostListeners will be executed on load with the event from state void (fromState: "void"), I don't know if this can be prevented from the animation declaration or if you only need to make a conditional inside the HostListeners if you want to prevent something from happening.