X Tutup
The Wayback Machine - https://web.archive.org/web/20220122221745/https://github.com/angular/angular/issues/44101
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Animation not working when combined query selector with tokens #44101

Open
thirumanidev opened this issue Nov 6, 2021 · 5 comments
Open

Animation not working when combined query selector with tokens #44101

thirumanidev opened this issue Nov 6, 2021 · 5 comments

Comments

@thirumanidev
Copy link

@thirumanidev thirumanidev commented Nov 6, 2021

Which @angular/* package(s) are the source of the bug?

animations

Is this a regression?

No

Description

I'm trying to animate child element with query selector(class name) & token(:enter),
but it throws error as follwoing
_ERROR
Error: Unable to process animations due to the following failed trigger transitions
@animation1 has failed due to:

  • query(".text4:enter") returned zero elements. (Use query(".text4:enter", { optional: true }) if you wish to allow this.)_

I mean it:
https://angular.io/api/animations/query#usage-notes

Please provide a link to a minimal reproduction of the bug

https://stackblitz.com/edit/angular-ivy-rtayah?file=src/app/app.component.ts

Please provide the exception or error you saw

ERROR
Error: Unable to process animations due to the following failed trigger transitions
@animation1 has failed due to:

- `query(".text4:enter")` returned zero elements. (Use `query(".text4:enter", { optional: true })` if you wish to allow this.)

Please provide the environment you discovered this bug in

Angular CLI: 11.2.7
Node: 14.17.4
OS: win32 x64

Angular:
...
Ivy Workspace:

Package                      Version
------------------------------------------------------
@angular-devkit/architect    0.1102.7 (cli-only)
@angular-devkit/core         11.2.7 (cli-only)
@angular-devkit/schematics   11.2.7 (cli-only)
@schematics/angular          11.2.7 (cli-only)
@schematics/update           0.1102.7 (cli-only)

Anything else?

No response

@mslooten
Copy link

@mslooten mslooten commented Nov 7, 2021

I think you need to either let the animation control the visibility of your child element (look into sequence or stagger), or create a separate trigger for your element. Right now, within your current animation the element is not found because Angular doesn't render it yet (because of the if-statement). Your example looks like it should all be controlled from the animation, like a sequence of events. However, if you just want a condition to control the animation, you can add a separate trigger: https://stackblitz.com/edit/angular-ivy-vsa8b4

@thirumanidev
Copy link
Author

@thirumanidev thirumanidev commented Nov 8, 2021

Hi @mslooten, thanks for your quick reply.

I think, the token(:enter, :leave) can control the visibility or presence in the DOM for an element.
And according to the angular.io document, it should have worked, right?

@ngbot ngbot bot added this to the needsTriage milestone Nov 8, 2021
@mslooten
Copy link

@mslooten mslooten commented Nov 11, 2021

Hi @thirumanidev, ah I understand. Looking at the docs it should be possible, the usage notes example is basically what you're trying to do.

Edit:
I did manage to get it working in your example by moving the timer function to the ngOnInit hook instead of having it in the constructor. I think that's better anyway. In this case, because the code is in the constructor, it's running before Angular has finished initialising all data-bindings.

@thirumanidev
Copy link
Author

@thirumanidev thirumanidev commented Nov 14, 2021

Hi @mslooten,
I tried your idea in my example, moved the timer call from constructor to ngOnInit, it doesn't work.

@dario-piotrowicz
Copy link
Contributor

@dario-piotrowicz dario-piotrowicz commented Nov 21, 2021

Hi @thirumanidev please check your stackblitz and notice that the error in the console appears right away and not when you set boo to true (setting boo to true doesn't actually trigger any sort of animation as you are not bounding boo to your trigger in any way)

So when your div component enters the DOM, its * => * transition gets triggered and in it the queries will be executed, including the query(".text4:enter", [ but at that point the .text4 element isn't actually present (because boo starts as false), so I do think that this is totally the expected behaviour

Am I missing something? 🤔


PS I am not too sure what you mean with the following:

I think, the token(:enter, :leave) can control the visibility or presence in the DOM for an element.
And according to the angular.io document, it should have worked, right?

But just to clarify, the query function only "queries"/"looks for" elements, it doesn't affect at all their presence or lack thereof in the DOM

@ngbot ngbot bot removed this from the needsTriage milestone Nov 25, 2021
@ngbot ngbot bot added this to the Backlog milestone Nov 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants
X Tutup