question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ngIf="false" will prevent transition(":leave") animation

See original GitHub issue

🐞 bug report

This ticket summarizes my findings to the issue described bellow. I´m aware that there are similar reports already, but none of them quite fit my problem.

Affected Package

The issue is likely caused by package @angular/animations

Is this a regression?

Yes, the previous version in which this bug was not present was: 7.2.7 according to this comment: Downgrading didn´t fix it for me though.

Description

I´m trying to add and remove an element to the DOM using *ngIf="someValue". I want to be able to play a fade-in animation using [@animation] when it get´s added to the DOM-tree. This works fine using

trigger('animation', 
transition(":enter", [...])
)

👍

According to https://angular.io/guide/animations this should work for :leave too.

For elements entering or leaving a page (inserted or removed from the DOM), you can make the animations conditional. For example, use *ngIf with the animation trigger in the HTML template.

Sadly, it doesn´t. 👎

According to this old Stackoverflow post

*ngIf removes the element from the DOM when the expression becomes false. You can’t have a transition on a non-existing element.

❓ If that´s the case, :leave (* => void) wouldn´t work at all? Am I missing something or is it a bug?

🔬 Minimal Reproduction

Will follow 🤷‍♀

🌍 Your Environment

Angular Version:



Angular CLI: 7.3.9
Node: 10.15.3
OS: darwin x64
Angular: 7.2.15
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router, service-worker

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.13.9
@angular-devkit/build-angular     0.13.9
@angular-devkit/build-optimizer   0.13.9
@angular-devkit/build-webpack     0.13.9
@angular-devkit/core              7.3.9
@angular-devkit/schematics        7.3.9
@angular/cdk                      7.3.7
@angular/cli                      7.3.9
@angular/material                 7.3.7
@angular/pwa                      0.12.4
@ngtools/webpack                  7.3.9
@schematics/angular               7.2.4
@schematics/update                0.13.9
rxjs                              6.3.3
typescript                        3.2.4
webpack                           4.29.0

Anything else relevant? Possibly related issues: #29509, #29496

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:4
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
2martenscommented, Aug 25, 2021

This issue seems to persist even in Angular 12. In my case the ngIf is on the div of the animation. But only the enter animation is played.

Layout:

<section *ngFor="let item of items; let idx = index">
  <div>
    <button (click)="toggleOpen(idx)">Button</button
  </div>
  <div *ngIf="isOpen(idx)" @ngIfAnimation>
  <!-- content -->
  </div>
</section>
1reaction
Ocean-Bluecommented, Jun 19, 2020

Any update about this issue? I am on version 9.1.10, and seems like the issue still exists.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Animations on child elements don't fire :leave if the host ...
The ones that help to make :leave animation work on child elements are query and animateChild . ... And definition of transition for...
Read more >
Animating Angular's *ngIf and *ngFor | by Jared Youtsey
This means that we are animating to the new style over 0.3 seconds, and we are easing out, or coming to a gentle...
Read more >
Animations on child elements don't fire :leave if the host ...
I am trying to create an entry / exit animation for a slide menu. ... don't fire :leave if the host component is...
Read more >
Angular Ngif Animation Fails - ADocLib
I have a tooltip component with animations in which the :enter animation ngIffalse will prevent transition:leave animation #30732.
Read more >
Using No-Op Transitions To Prevent Animation During The ...
Ben Nadel demonstrates how to use a no-op (No Operation) transition in Angular 5.2.6's Browser Animations module to block animations during ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found