angular: `animateChild` does not work when used in router transitions
š bug report
Affected Package
The issue is caused by package @angular/animationsIs this a regression?
It never workedDescription
animateChild
does not work when used in router transitions as explained in the official documentation
animateChild
should start child transitions but nothing happens.
š¬ Minimal Reproduction
āContent page xā should be red and slowly switch back to black when switching page.
Remove the [@routerAnimations]="prepareRoute(outlet)"
and switch page to confirm that the animation is working but just not triggered.
š„ Exception or Error
No error shown.
š Your Environment
Angular Version:
@angular@7.2.15
Anything else relevant?
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 6
- Comments: 30 (15 by maintainers)
Commits related to this issue
- docs(animations): update developers on state of package Notify developers that @angular/animations package has been "significantly de-prioritized" `animateChild` documentation now references #30477 ... — committed to michaelurban/angular by deleted user 3 years ago
- docs(animations): update developers on state of package Notify developers that @angular/animations package has been "significantly de-prioritized" `animateChild` documentation now references #30477 ... — committed to michaelurban/angular by deleted user 3 years ago
- docs(animations): update developers on state of package (#44014) Notify developers that @angular/animations package has been "significantly de-prioritized" `animateChild` documentation now reference... — committed to angular/angular by deleted user 3 years ago
- docs(animations): update developers on state of package (#44014) Notify developers that @angular/animations package has been "significantly de-prioritized" `animateChild` documentation now reference... — committed to angular/angular by deleted user 3 years ago
- docs(animations): amend incorrect information regarding animateChild Amend incorrect information present in the angular.io animations documentation stating that animateChild does not work with route ... — committed to dario-piotrowicz/angular by dario-piotrowicz 3 years ago
- docs(animations): amend incorrect information regarding animateChild Amend incorrect information present in the angular.io animations documentation stating that animateChild does not work with route ... — committed to dario-piotrowicz/angular by dario-piotrowicz 3 years ago
- docs(animations): amend incorrect information regarding animateChild Amend incorrect information present in the angular.io animations documentation stating that animateChild does not work with route ... — committed to dario-piotrowicz/angular by dario-piotrowicz 3 years ago
- docs(animations): amend incorrect information regarding animateChild Amend incorrect information present in the angular.io animations documentation stating that animateChild does not work with route ... — committed to dario-piotrowicz/angular by dario-piotrowicz 3 years ago
- fix(animations): allow enter animation of every inserted element currently in the animations package not all newly inserted elements are treated as entering ones, thus querying them via ':enter' does... — committed to dario-piotrowicz/angular by dario-piotrowicz 3 years ago
- fix(animations): allow enter animation of every inserted element currently in the animations package not all newly inserted elements are treated as entering ones, thus querying them via ':enter' does... — committed to dario-piotrowicz/angular by dario-piotrowicz 3 years ago
- fix(animations): allow enter animation of every inserted element currently in the animations package not all newly inserted elements are treated as entering ones, thus querying them via ':enter' does... — committed to dario-piotrowicz/angular by dario-piotrowicz 3 years ago
- fix(animations): allow enter animation of every inserted element currently in the animations package not all newly inserted elements are treated as entering ones, thus querying them via ':enter' does... — committed to dario-piotrowicz/angular by dario-piotrowicz 3 years ago
- docs(animations): amend incorrect information regarding animateChild Amend incorrect information present in the angular.io animations documentation stating that animateChild does not work with route ... — committed to dario-piotrowicz/angular by dario-piotrowicz 3 years ago
- docs(animations): remove incorrect information regarding animateChild Remove incorrect information present in the angular.io animations documentation stating that animateChild does not work with rout... — committed to dario-piotrowicz/angular by dario-piotrowicz 3 years ago
- docs(animations): remove incorrect information regarding animateChild (#44216) Remove incorrect information present in the angular.io animations documentation stating that animateChild does not work ... — committed to angular/angular by dario-piotrowicz 3 years ago
- docs(animations): remove incorrect information regarding animateChild (#44216) Remove incorrect information present in the angular.io animations documentation stating that animateChild does not work ... — committed to angular/angular by dario-piotrowicz 3 years ago
@dario-piotrowicz Fantastic news that this may be a query issue. A mild inconvenience can be a simple hurdle to one dev and a brick wall to another, especially when the docs say it should work.
You have no idea how grateful I am that youāre working on this.
Mike awarded Dario:š (participant)
And Iāll have a freshly mintedš„1st place medal for you at this ticketās closing ceremony!
Thanks @dario-piotrowicz - as discussed I will close this issue and we should continue with #44253
Hi, Iāve been spending a bunch of time on this, and Iāve got a bit down a rabbit hole, but I just found out something I find it pretty interesting so I thought of sharing it here as someone could find it interesting too š
Iām 100% that it is a query thing and itās not related to routing or anything of the sort, it is related on how angular adds elements to the dom, and based on that they can be detected/queried as entering elements for animation or not, the issue here is that the elements detected as āenteringā for animation are either the componentās host or elements with structural directives, which our child elements are not
this made me find a new workaround (if you want to use
":enter"
and not"@*"
, etcā¦), if we just put a structural directive to the child elements we want to animate, angular will just handle them differently and they will be actually detected as entering query elementsAny structural directive will do, like an
*ngIf="true"
or a useless*ngFor
:(as you can see in this new stackblitz: https://stackblitz.com/edit/angular-lndzuf?file=src%2Fapp%2Fapp.component.html)
So yeah itās not like itās solved or anything, I just wanted to share this small tidbit, and also provide a new (simpler? š¤·āāļø) workaround to get the animation working š
@petebacondarwin
@angular/*
packages seem to be very tightly controlled by Google. Why not communicate that@angular/animations
is, and we can quibble about wording here, unmaintained. Iād wager that those who rely on it would like to know that it has been āsignificantly de-prioritizedā quietly. Why not loudly request community or corporate support?We know where the bugs, flaws, and deficits are. Not sounding the alarm about them outside of issue trackers and using an āALL ENGINES GO!ā tone in the documentation/communications is unhelpful and infuriating for the people who have to dig around in the code to see whatās really going on.
I love Angular. However, the communication issues (policies?) combined with actual bugs make me understand why thereās no amount of money most JS, React, and Vue developers can be paid to learn Angular.
Itās a shame! Angular+NgRx are the best way to structure code for the web. Iāve described using Angular as running with rocks in my shoes. Very nice shoes that help you run very fast to be sure, but, the rocks eventually leave your toes bloody.
Angular has a lot of issues. More than most open source projects. While features like optional modules have been getting a lot of attention, modules are not one of the issues keeping developers from adopting or learning Angular. Poor communication, bugs, and moving slowly on common functionality/features large and small (Zone.js+async/await, no passive HostListeners w\o hacks, etc.) are keeping developers out.
Itās also hard to get a deep insight into whatās actually going on with Angular development. That information is scattered across GitHub, Twitter, Medium, a smattering of newsletters, courses, and videos, or, is internal to Google and not communicated to external developers at all.
The Angular blog hasnāt been updated since early June and the Twitter account is often surface level DR/PR. Reading the Twitter account, the most robust Angular news aggregator, youād have no idea that a major Angular package like animations is unmaintained. How do you stay truly informed?
From the outside it seems like the day-to-day problems/bugs are here to stay.
Iāve never seen a large open source project run like Angular. Itās not working.
Hereās a positive example: This is how I keep up to date with Django development:
Typically there are a few posts similar to this on the homepage that contains a link to extensive, developer friendly, release notes for each release.
To compare, Angularās homepage does not feature the latest releases (LTR, latest, or dev/next) and Angularās release notes are less useful. New features link to, sometimes, several GitHub issues and release notes are not linked anywhere on the Angular homepage. I think this is by design? Hiding the version numbers to keep from scaring off new developers?
I think itās time for an Angular Foundation similar in structure to Django, Python, or GNOMEās. Thoughts?
Yes this all sounds good. Please go ahead @dario-piotrowicz - and thanks again!!
Iāll close this issue once you create the new one.
Iām unable to implement my teamās visual+motion design using Angular animations because basic, documented, functionality is broken. Itās been two years since this featured was accepted as broken, is there any kind of an update?
By the way, this would also explain why your other workaround solves the problemā¦
When the parent view is āenteredā it will evaluate the expressions on any structural directives within its template. If any of those result in their view being displayed, those views will also receive the
:enter
transition.So if we think about it like this:
:enter
and:leave
are only triggered on the root element of a view that is being added or removed, then it makes sense that querying for:enter
on child elements of a view that is entering will not return anything.In that case, the way I found for it to work was to just scope the query to be elements that are contained by
:enter
. In other words:This works in the standard example we are using here: https://stackblitz.com/edit/angular-w6muoa?file=src%2Fapp%2Fanimations.ts
And if you wanted to be more precise then you could do something like:
See https://stackblitz.com/edit/angular-kljx26?file=src%2Fapp%2Fanimations.ts
@dario-piotrowicz I did not understand it like that at first. It makes sense now.
@Ploppy3 Thank you very much for your input š
Yes I agree with you that
@*
being ok but:enter
not, does not feel very correct, but it sort of turns the bug from ābroken functionality with no workaroundsā to āmild inconvenience with an easy workaroundā from my point of view šAlso as I said I still want to investigate the querying issue, hopefully something interesting will turn out from that šš
Anyway thanks a bunch, weāll take it from here then š
Same too š¦
Running into the same issue
Iām having the exact same problem. Iāve tried just about every possible way I can think of to get animations to run on the pages that are entering/leaving and it just ignores them.
Edit 1:
It appears to ignore all child animations completely if the animation is on an element of the page being transitioned. However if I apply an animation to the page component via host binding, then use animateChild in THAT trigger (essentially going 2 levels deep with animateChild), it does something. Unfortunately, what it does is completely remove the leaving page instantly with no animations at all. But hey, at least something changedā¦
@Ploppy3 This is not a bug. Here is a updated link. which works as you expected. stackblitz The reason why the div is not animated is when your page is in a enter state, the div element is already entered in its parent earlier ! so the ā@redToBlackā bind to the div wonāt work as expected,because the div is not match the ā:enterā state.
The right way to do is bind the āredToBackā to the _ page_: and modify the animation definition using query to find the div ,then animate it ļ¼