我想点击按钮角js执行休息api请求

时间:2016-07-15 12:48:25

标签: angularjs rest http angular-material

我想点击按钮执行休息api并显示加载栏,直到请求完成并在mddialog中显示请求结果。我是新手,我不知道如何继续。

任何答案都会有所帮助。

$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 个答案:

答案 0 :(得分:2)

您的点击操作

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

<强>控制器

$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.
    });
}

加载栏

您只需要安装它 Angular loader它将为您完成其余的工作