I'm trying to toggle (hide/show) a loading gif on every new route, so my logic would be:
- routeChangeStart = show loading gif
- routeChangeSuccess = hide loading gif
This is my code:
//ANGULAR
app.run(function($rootScope) {
$rootScope.layout = {};
$rootScope.layout.loading = false;
$rootScope.$on('$routeChangeStart', function() {
//show loading gif
$rootScope.layout.loading = true;
});
$rootScope.$on('$routeChangeSuccess', function() {
//hide loading gif
$rootScope.layout.loading = false;
});
$rootScope.$on('$routeChangeError', function() {
//hide loading gif
alert('wtff');
$rootScope.layout.loading = false;
});
});
//HTML
<img src="img/loading.gif" ng-hide="!layout.loading"/>
it is strange cause this works for 3/4 routes changed then it stop working while changing routes :O
what it could be?
HERE IS A LIVE EXAMPLE thanks to @Rob Sedgwick : http://plnkr.co/edit/ZpkgRhEAoUGlnXjbLb8b