我想在单击按钮 angular js 时执行 rest api 请求 [英] I want to perform a rest api request on click of a button angular js
本文介绍了我想在单击按钮 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.
});
}
加载栏
你只需要安装这个Angular loader,剩下的事情就交给它了
You just need to install this Angular loader and it will do the rest for you
这篇关于我想在单击按钮 angular js 时执行 rest api 请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文