trying to add loading wheel using angular when i make ajax call?

后端 未结 4 1058
小鲜肉
小鲜肉 2021-01-26 03:03

I am trying to implement loading wheel directive when we make ajax call so during the response time i want to display loading wheen, With below code i do not see any error neith

4条回答
  •  野性不改
    2021-01-26 04:02

    Jeesk. Most of these answers seem like overkill, why not just include the image in your controller view and toggle it with an ng-show or ng-if?

    ( Please pardon my use of the API or whatever. Obviously the $http request should be abstracted into a service or something. I did this quickly and it's been a bit since I have worked with Angular 1)

    angular.module("whatever")
      .controller("thing", function($scope, $http /* and whatever else*/) {
    
    
      $scope.isShowing = false;
    
      $scope.makeAJAXCall = function() {
        $scope.isShowing = true;
    
        $http.get("whatever.com")
          .success(function() {
          $scope.isShowing = false;
        });
    
      }
    });
    

    And the HTML:

提交回复
热议问题