Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

ngAnimate doesn't trigger enter method on first page load #10536

Closed
eeglbalazs opened this issue Dec 20, 2014 · 11 comments
Closed

ngAnimate doesn't trigger enter method on first page load #10536

eeglbalazs opened this issue Dec 20, 2014 · 11 comments

Comments

@eeglbalazs
Copy link

After upgrading to v1.3.8 ngAnimate doesn't trigger enter method on first page load.
I'm using Javascript based animations with the standard Angular Router.

Like:

ngModule.animation('.an-reveal', function () {
    return {
      enter: function(element, done) {
        element.velocity('fadeIn', { delay: 300, duration: 600, complete: done })
        return function() {
          element.stop()
        }
      },
      leave: function(element, done) {
        element.velocity('fadeOut', { duration: 300, complete: done })
        return function() {
          element.stop()
        }
      }
    }
  })

and I have <main ng-view class="an-reveal"></main>

@grabbou
Copy link

grabbou commented Dec 21, 2014

Actually, it is a normal Angular approach that has been introduced a while ago. You can read more about the details here -> #5130. There's a quick 'dirty-hack' mentioned in the last comment there showing how to make that working again. I've recently needed to enable that in order to present enter animation of the whole app to the users.

Note: Remember that this is still dirty hack that may stop working in the future or create additional bugs so comment that line really nicely in your app and always check when upgrading to a newer Angular version.

@petebacondarwin
Copy link
Contributor

@matsko - should we make this easier to achieve?

@eegl - an alternative less hacky approach is to initialize the things that you want to be animated on start up via a $timeout. See http://plnkr.co/edit/2kRgrYYcJvtbXwNXn9n2?p=preview

@eeglbalazs
Copy link
Author

@grabbou , @petebacondarwin thank you both for your suggestions and explaining what's going on!

I've ended up with the following code, which - I believe - is hacky too, but I've only needed to add one line, without changing anything else (basically manually triggering the same animation as I have on 'enter'):

ngModule.animation('.an-reveal', function () {
   angular.element('.an-reveal').velocity('fadeIn', { delay: 300, duration: 600})
    return {
      enter: function(element, done) {
        element.velocity('fadeIn', { delay: 300, duration: 600, complete: done })
        return function() {
          element.stop()
        }
      },
      leave: function(element, done) {
        element.velocity('fadeOut', { duration: 300, complete: done })
        return function() {
          element.stop()
        }
      }
    }
  })

@grabbou
Copy link

grabbou commented Dec 22, 2014

@petebacondarwin @MatasKo Maybe additional argument when declaring animations with ngAnimate, like "animateOnStartup: {Boolean} | false" by default ?

@matsko
Copy link
Contributor

matsko commented Dec 22, 2014

@eegl @grabbou if you place the following attribute on the body element then animations on load should work.

<body ng-animate-children="exp">

And set exp=true once the application loads then it should work.

@lgalfaso
Copy link
Contributor

lgalfaso commented Jan 2, 2015

from the comments, it is my understanding that there is nothing else to be done for this issue. If there is something else that needs attention, feel free to reopen the issue

@lgalfaso lgalfaso closed this as completed Jan 2, 2015
@glebmachine
Copy link

year passed...
This is still a problem, does anybody have any news?

@gkalpak
Copy link
Member

gkalpak commented Dec 23, 2016

@glebmachine, what news do you expect? Based on the comments, the conclusion was that this is working as expected, there is a way to change the default behavior if you wish and there is nothing more to do.

If you are having issues with latest versions, please open a new issue describing the problem (and please reference this issue for context).

@hejiaji
Copy link

hejiaji commented Feb 21, 2017

@glebmachine The best way for now is using setTimeout as a workround

@glebmachine
Copy link

glebmachine commented Feb 21, 2017 via email

@oemueller
Copy link

oemueller commented Sep 25, 2017

Using this snippet animations are also played on page load:
myModule.run(function($animate) { $animate.enabled(true); });
Source

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

9 participants