Angular js - show/hide loading gif every new route

前端 未结 2 1471
太阳男子
太阳男子 2020-12-24 13:18

I\'m trying to toggle (hide/show) a loading gif on every new route, so my logic would be:

  • routeChangeStart = show loading gif
  • routeChangeSuccess = hi
2条回答
  •  再見小時候
    2020-12-24 14:17

    ( A little too much to put in a comment )

    I set the code up and saw that the loading variable was not updated each time and was due to the template caching, I guess the 'RouteChange' is not triggered.

    Disabling the template caching will let your code run each time ..

    app.run(function($rootScope, $location, $anchorScroll, $routeParams,$templateCache) {
    
       $rootScope.$on('$viewContentLoaded', function() {
           $templateCache.removeAll();
        });
    
       ....
    

提交回复
热议问题