Repository navigation
Description
Which @angular/* package(s) are the source of the bug?
core, animations
Is this a regression?
No
Description
I wanted to migrate a simple dialog with a backdrop from @angular/animation to the new API. The requirements are:
- Structure: backdrop > container > content
- The container animation must be longer than the backdrop animation
- I need to know when the animations (both enter and leave) have finished
1. animate.leave doesn't emit animationend
Referring to the comment (#62212 (reply in thread)), the preferred way to react to animation events is now through native browser events. Unfortunately, in the case of animate.leave, it seems that neither animationend nor animationcancel is emitted.
2. Nested animations
I want to add animations to the 'backdrop ' and 'container'. I've tested two ways to achieve my goal:
- Nested attributes
animate
<backdrop animate.enter="..." animate.leave="...">
<container animate.enter="..." animate.leave="...">
...content
</container>
</backdrop>
- Nested styles with animation
<style>
backdrop.enter { animation: ... }
backdrop.enter > container { animation: ... }
backdrop.leave { animation: ... }
backdrop.leave > container { animation: ... }
</style>
<backdrop animate.enter="..." animate.leave="...">
<container>
...content
</container>
</backdrop>
In the first approach, animate.enter works correctly, but animate.leave for the container does not fire at all.
In the second attempt, the enter and leave animations for the container are interrupted.
To be honest, I'm not sure how this situation with nested animations should work, but I think the more natural approach is the first one, and the nested 'animate' should also be notified when the parent is destroyed. The question remains whether a nested animation should prevent its parent from being destroyed.
I am aware that I can achieve this with (animate) or a second approach with animations of equal duration.
3. Class-based animation termination
According to documentation (https://angular.dev/guide/animations#event-bindings-functions-and-third-party-libraries):
If you don't call animationComplete() when using animate.leave, Angular calls the function automatically after a four-second delay.
This information is incomplete, as animations based on CSS classes also terminate after 4 seconds. This can be misleading, as the documentation suggests that the timeout only serves as a safeguard against a missing call animationComplete().
Please provide a link to a minimal reproduction of the bug
Please provide the exception or error you saw
Please provide the environment you discovered this bug in (run ng version)
Angular CLI: 20.2.0
Node: 22.17.1
Package Manager: npm 10.9.2
OS: win32 x64
Angular: 20.2.1
... animations, common, compiler, compiler-cli, core, elements
... forms, language-service, platform-browser
... platform-browser-dynamic, router
Package Version
---------------------------------------
@angular-devkit/architect 0.2002.0
@angular-devkit/build-angular 20.2.0
@angular-devkit/core 20.2.0 (cli-only)
@angular-devkit/schematics 20.2.0
@angular/cdk 20.2.0
@angular/cli 20.2.0
@schematics/angular 20.2.0
rxjs 7.8.2
typescript 5.8.3
Anything else?
No response
Activity
thePunderWoman commentedon Aug 26, 2025
@CoreAngel Thanks for this report. There's a few things here:
animate.leaveshould emit animationend. If it's not, that's something we'll need to address, but in order to actually remove the element, internally it relies on animationend. So it has to emit it. We do cancel bubbling though, and maybe that's why you're not seeing it. We can maybe revisit if we should allow bubbling to continue. We'll take a look at the repro to see what's happening.This one is complicated, but we'll look at your repro and see what's happening.
This is a good callout. That timeout was intended solely for event based binding protection, and probably should not affect non-event based bindings. We can look at addressing this.
thePunderWoman commentedon Aug 26, 2025
I can confirm that
animationendis not firing onanimate.leave. This is definitely a bug. I'm going to create a separate issue to track. The nested animation one is more complicated. Essentially there's a waterfall happening where the parent node animation fires when destroy is called. So that animation runs, and then once it's done the destroy is called on the child node. However...once that parent animation is done, the node is removed. So the child node is removed immediately along with it.This is definitely something we'll need to fix, but it's a more complicated one. In the meantime, definitely use the (event) version or nested version the to achieve your goals. The nested version behaves the way it does because it's looking at the element that the
animate.enteroranimate.leaveis on to know when to remove the element or class. So unless the parent element has the same or longer animation duration, the child animation will always be interrupted.[-]animate.leave doesn't emit animationend, nested animation and timeout docs[/-][+]nested animations don't behave as expected[/+]thePunderWoman commentedon Aug 26, 2025
I've created #63391 to track the
animationendbug.thePunderWoman commentedon Aug 26, 2025
@CoreAngel #63393 should address the timeout behavior and ensure it only applies to
(animate.leave)usages.thePunderWoman commentedon Aug 27, 2025
@CoreAngel So the reason animation events are not firing on the custom binding has to do with timing of when leave animations happen. It's technically happening post component destroy, which means all the event bindings on the component level are cleaned up already. They're getting emitted internally to the nodes that were manually subscribed for animations to work, but they will never emit all the way up to your custom binding due to the current timing. This will require a larger refactor to fix. Stay tuned.
refactor(core): dispatch enter and leave animations at the right times
13 remaining items
refactor(core): dispatch enter and leave animations at the right times
refactor(core): dispatch enter and leave animations at the right times
refactor(core): dispatch enter and leave animations at the right times
refactor(core): dispatch enter and leave animations at the right times
refactor(core): dispatch enter and leave animations at the right times
refactor(core): dispatch enter and leave animations at the right times
refactor(core): dispatch enter and leave animations at the right times
refactor(core): dispatch enter and leave animations at the right times
refactor(core): dispatch enter and leave animations at the right times
refactor(core): dispatch enter and leave animations at the right times
refactor(core): dispatch enter and leave animations at the right times (
refactor(core): dispatch enter and leave animations at the right times (
angular-automatic-lock-bot commentedon Oct 11, 2025
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.