我想在单击按钮angular js时执行rest api请求 [英] I want to perform a rest api request on click of a button angular js

查看:73
本文介绍了我想在单击按钮angular js时执行rest api请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在单击按钮时执行rest api,并显示一个加载栏,直到请求完成,并在mddialog中显示请求的结果.我是新来的,我不知道该如何进行.

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

推荐答案

您的点击操作

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

加载栏

您只需要安装此 角度加载器,它将为您完成其余工作

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

这篇关于我想在单击按钮angular js时执行rest api请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆