[angularjs] Angularjs loading screen on ajax request

In reference of this answer

https://stackoverflow.com/a/17144634/4146239

For me is the best solution but there's a way to avoid use jQuery.

_x000D_
_x000D_
.directive('loading', function () {_x000D_
      return {_x000D_
        restrict: 'E',_x000D_
        replace:true,_x000D_
        template: '<div class="loading"><img src="http://www.nasa.gov/multimedia/videogallery/ajax-loader.gif" width="20" height="20" />LOADING...</div>',_x000D_
        link: function (scope, element, attr) {_x000D_
              scope.$watch('loading', function (val) {_x000D_
                  if (val)_x000D_
                      scope.loadingStatus = 'true';_x000D_
                  else_x000D_
                      scope.loadingStatus = 'false';_x000D_
              });_x000D_
        }_x000D_
      }_x000D_
  })_x000D_
_x000D_
  .controller('myController', function($scope, $http) {_x000D_
      $scope.cars = [];_x000D_
      _x000D_
      $scope.clickMe = function() {_x000D_
        scope.loadingStatus = 'true'_x000D_
        $http.get('test.json')_x000D_
          .success(function(data) {_x000D_
            $scope.cars = data[0].cars;_x000D_
            $scope.loadingStatus = 'false';_x000D_
        });_x000D_
      }_x000D_
      _x000D_
  });
_x000D_
<body ng-app="myApp" ng-controller="myController" ng-init="loadingStatus='true'">_x000D_
        <loading ng-show="loadingStatus" ></loading>_x000D_
  _x000D_
        <div ng-repeat="car in cars">_x000D_
          <li>{{car.name}}</li>_x000D_
        </div>_x000D_
        <button ng-click="clickMe()" class="btn btn-primary">CLICK ME</button>_x000D_
  _x000D_
</body>
_x000D_
_x000D_
_x000D_

You need to replace $(element).show(); and (element).show(); with $scope.loadingStatus = 'true'; and $scope.loadingStatus = 'false';

Than, you need to use this variable to set the ng-show attribute of the element.