I am using angular 1.6.5 for my angular application and came across very strange behavior.
I want to achieve: when ngroute changes, I have to remove the active class from the current view, wait for the vacation animation to complete, and then add the active class to the new view.
I installed the application and routes in config.
var app = angular.module('app', ['ngAnimate', 'ngRoute']); app.config(function ($routeProvider) { $routeProvider .when('/', { templateUrl:"home.html", reloadOnSearch:false }) .when('/about-us', { templateUrl:"about.html", reloadOnSearch:false }) .when('/contact', { templateUrl:"contact.html", reloadOnSearch:false }) .otherwise({ template : "<h1>None</h1><p>Nothing has been selected</p>" }); });
I have a service that stores animation timings and booleans showing the visibility of a view:
app.service('animationProperties', function () { this.animationTimings = { views: 1000 }; this.visibility = { view : false }; });
I have one main controller with a simple debugging function and one onRouteChangeStart function, which should remove the active class from the current view (making visibility a logical false):
app.controller('MainCtrl', function ($scope, $window, $location, animationProperties) { $scope.animationProperties = animationProperties; $scope.$on('$routeChangeStart',function () { animationProperties.visibility.view = false; }); $scope.toggleActive = function(){ $scope.animationProperties.visibility.view = !$scope.animationProperties.visibility.view; } });
Lastly, ngAnimate, which waits for the vacation animation to complete, then deletes the current view (using the done () method) and re-introduces the new view, making the appearance logical: true /
app.animation('.view', function($timeout, animationProperties) { return { enter: function(element, done) { $timeout(function () { animationProperties.visibility.view = true; $timeout(function () { done(); }, animationProperties.animationTimings.views);
Here is the plunker
The first time you switch pages (from navigation), you will see that everything works fine, but when you go to pages, the second class of viewing time does not update, so the animation does not play. During debugging, you can clearly see that the boolean visibility is updated correctly, but the ng class is not updated when exiting the view.
Your help would be greatly appreciated.