I want to perform a rest api request on click of a

2019-09-16 05:57发布

I want to perform a rest api on click of a button and show a loading bar until the request is completed and show the result of request in a mddialog . I am new to this I dont know how to proceed.

Any answers help would be appreciated.

$http({
    method: 'GET',
    url: url1
  }).then(function successCallback(response) {
    var confirm = $mdDialog.confirm()
      .title('Download as CSV')
      .textContent('You can download the csv by clicking below link')
      .ariaLabel('Download')
      .targetEvent(response.data.export_url)
      .ok('Download as CSV');
    $mdDialog.show(confirm);
    // this callback will be called asynchronously
    // when the response is available
  }, function errorCallback(response) {
    // called asynchronously if an error occurs
    // or server returns response with an error status.
  });

1条回答
地球回转人心会变
2楼-- · 2019-09-16 06:41

Your click action

<input type="button" ng-click="performCall()" />

Controller

$scope.performCall = function(){
    // Simple GET request example:
    $http({
      method: 'GET',
      url: '/someUrl'
    }).then(function successCallback(response) {
       // this callback will be called asynchronously
       // when the response is available
    }, function errorCallback(response) {
       // called asynchronously if an error occurs
       // or server returns response with an error status.
    });
}

The loading bar

You just need to install this Angular loader and it will do the rest for you

查看更多
登录 后发表回答