angular-ui-router-anim-in-out icon indicating copy to clipboard operation
angular-ui-router-anim-in-out copied to clipboard

Animation not working on load/reload

Open konpa opened this issue 9 years ago • 5 comments

Animations are not fired when I load/reload the page. Is it normal behavior or did I do something wrong?

konpa avatar Feb 04 '16 15:02 konpa

This is intentional behaviour - as described on the ui-router repo (sorry no link right now). The workaround to force this behaviour is to change to a blank state and back on load.

Let me know if you need an example

homerjam avatar Feb 04 '16 23:02 homerjam

Thanks for the fast answer :) I'm not sure to understand what you mean. A blank state that redirect to "normal" states automatically? But will it work when I reload non root path (like mysite.com/about)? It would be much appreciated if you could provide with an example :)

Really good work by the way! Thanks!

konpa avatar Feb 05 '16 08:02 konpa

The basic principle is like so:

// in app config

// configure blank state
$stateProvider.state('blankState', {});


// in app run (or main controller)

// record initial state (determined on first page load)
var initalState = [$state.$current.name, $stateParams];

// change to the blank state
$state.go('blankState');

// immediately change back to the initial state thus triggering the transition
$timeout(function(){
    $state.go.apply(null, initialState);
});

homerjam avatar Mar 11 '16 16:03 homerjam

When trying to use this technique, I get the error: The transition errored, detail: Error: Cannot transition to abstract state '').

I've tried it in a run block & in the main controller. I've tried it with the code as you've suggested it & also with the following code, neither successfully:

var initialState = $stateParams;
var currentName = $state.current.name;
$state.go('blankState');
$timeout(function(){
  $state.go(currentName, initialState);
});

The blank state is configured as you suggested. The error is from the second $state.go (or $state.go.apply). Do you have any suggestions, clues? Thanks!

rhclayto avatar Aug 06 '17 19:08 rhclayto

So I found out that animations on load work if you do the following:

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

From comments at https://github.com/angular/angular.js/issues/10536#issuecomment-67877870 .

rhclayto avatar Aug 06 '17 22:08 rhclayto