ngView animation enter is not firing on page load. #15589
Description
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:
var app = angular.module('app', ['ngAnimate', 'ngRoute']);
app.animation('.view', function () {
return {
enter : function (element, done) {
alert('enter');
done();
},
leave : function (element, done) {
alert('leave');
done();
}
}
});
//Config
app.config(function ($routeProvider, $locationProvider, $httpProvider){
$routeProvider.when('/test.php',{
template : function () {
return "<div>Welcome to test page</div>";
}
});
$routeProvider.when('/test.php/:path',{
template : function () {
return "<div>Inside page</div>";
}
});
$locationProvider.html5Mode({enabled: true, requireBase: true});
});
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:
$routeProvider.when('/test.php',{
template : function () {
return "<div>Welcome to test page</div>";
},
resolve: {
message: function ($timeout, $q) {
console.log('asdasa')
return $q(function(resolve){
$timeout(function () {
resolve('message');
},1000);
});
}
}
});
$routeProvider.when('/test.php/:path',{
template : function () {
return "<div>Inside page</div>";
},
resolve: {
message: function ($timeout, $q) {
return $q(function(resolve){
$timeout(function () {
resolve('message');
},1000);
});
}
}
});
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:
app.run(function($animate) {
$animate.enabled(true);
});
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!