-
Notifications
You must be signed in to change notification settings - Fork 27.6k
ngView animation enter is not firing on page load. #15589
Comments
@gogachinchaladze, can you create runnable demo that reproduced the problem (preferrably using CodePen, plnkr or a similar service)?
Also clarify what "strange behavior" means. |
http://jsbin.com/yifunodota/edit?html,js,output Here is the fiddle I'm talking about. I'll examine the behavior deeper and write it too :) |
I don't see something unexpected tbh. [As documented] animations are disabled upon bootstrap (and wait for templates to be downloaded and 1.5 digests before getting enabled). When the template is readily available during app bootstrap, animations are still disabled, so they don't run for the initial This is what I observed (and is expected behavior). Are you seeing something different? Can you detail the steps to reproduce the issue? |
Yes, you are right. Just one more thing: When I go to the page first time, $animate.enabled(true) doesn't work on safari. But when I reload the page being on the same tab, it does. Sorry I cannot create JsBin for this, as it's so browser specific. |
What version of Safari? I tried your jsBin on Safari 10 yesterday and it worked as expected (I think). |
Can you please see the updated jsBin ? The problem is that when I enable animation on view element only, the enter event doesn't fire, but when I enable animation on whole page, it does. While debugging, I even found out that animation on view element is enabled on bootstrap, but the whole page animation is disabled, so I'm not surprised that enabling only view element animation doesn't help. But enabling animation on whole page is not the thing I want to do. |
When animations are globally disabled (via If you want to only enable animations on a specific element, you can generally use something like: $animate.enabled(document.body, false);
$animate.enabled(mySpecificElem, true); But in this case, you can't enable animations on the <body>
<div class="view-container">
<div class="view" ng-view></div>
</div>
</body> app.run(function ($animate) {
$animate.enabled(true);
$animate.enabled(document.body, false);
$animate.enabled(document.querySelector('.view-container'), true);
}) #14914 (once/if merged) will provide another way to handle this. |
Ok, got it. Done everything and works great in JSBIN But on real website it has the same problem. When I open a new tab and go to website, the animation enter still does not fire. I even created a simple index.html, without any excess code, and still the same problem occurred. |
😞 - No idea what might be causing the different behavior, sorry. Happy to look into it if you can provide a reproduction. In the meantime, I am going to close this, since everything seems to work as expected (at least on jsBin 😛). Feel free to continue the discussion below. |
Here is a link where you can test it: http://goga.lsapps.me/test.php In chrome it works well, but when I test it in safari, on first page load it doesn't fire, but if I reload on same tab, it does. you can see it on real website. Again, works well on chrome, but same problem on safari. Thank you so much for help! |
Have you tried replacing |
Yes I did, same problem :( |
On Chrome for example, it isn't run when the tab is not focused. This seems something browser-related. |
Yes, I noticed that too. |
Nothing new, yes? |
So, the difference is that in Safari For whatever reason, Safari sets |
Is there any way to always animate not depending on document.hidden? |
It is not directly supported (as part of the public API). The obvious hack outside Angular is to set We are using a private service to track the visibility of the document, so you can overwrite that; it's called app.value('$$isDocumentHidden', function() { return true; }); |
Yay! Finally, works well! Just one thing to note:
Hope nothing goes wrong with this hack! @gkalpak |
Doh! Glad it worked for you and that everything works as expected inside |
I'm using latest angular (v1.6.1), ngRoute and ngAnimate.
The thing is that ngView animation enter is not firing when you go to website (when the website loads first time).
Here is my code:
I've seen this issue here: #10536
That says that "it's a feature, not a bug". But the thing is that on production website, it sometimes fires and sometimes not (especially in safari and mobile browsers).
For example, when I make the template load slower:
Or with PHP:
sleep(1)
the enter event fires, but maybe when it is in the cache or when browser gets it quickly, it does not.
I tried several dirty hacks mentioned here but none of them works:
For example:
$rootElement.data("$$ngAnimateState").running = false;
Also this:
But it has a very strange behavior and in safari it doesn't help.
Thanks in advance and I'll be waiting for your help!
The text was updated successfully, but these errors were encountered: