如何显示叠加加载gif,同时完成我的http.Post in angular
How show overlay with loading gif while finish my http.post in angular
朋友们,我试着用ng-show(loading)添加div,当初始化我的控制器时,将false设置为loading,当用户点击按钮时:
<button ng-click="AddUser(user)">Yes</button>
$scope.AddUser = function(user) {
user.approved = true;
$scope.loading = true;
$http.get('/group/' + user.group).success(function(resp) {
$scope.error = "";
user.name = resp.name;
user.company = resp.company;
$http.post('/approvedUser', user).success(function(response) {
$scope.loading = false;
$location.path('/admin/listUsers');
}).error(function(response) {
$scope.error = "There was a problem!";
});
}).error(function() {
$scope.error = "Problem listing Groups";
});
};
我需要添加div叠加加载动画,而用户是创建的,这个过程有点慢,因为我调用外部API后,我希望用户不能使用系统来完成这个过程。
谢谢
在你的视图中定义一个潜水,在它里面应该有一个gif图像,像这样:
<div ng-if="status">
<img src="link of gif image" />
</div>
,然后在第一次加载页面时从控制器初始化状态变量
$scope.status = 0;
然后,对AddUser函数做一个小的修改:
$scope.status= 0; // initialize loading image parent div
$scope.AddUser = function(user) {
user.approved = true;
$scope.loading = true;
$scope.status= 1; // Show loading image
$http.get('/group/' + user.group).success(function(resp) {
$scope.error = "";
user.name = resp.name;
user.company = resp.company;
$http.post('/approvedUser', user).success(function(response) {
$scope.status= 0; // Hide loading image
$scope.loading = false;
$location.path('/admin/listUsers');
}).error(function(response) {
$scope.status= 0; // Hide loading image
$scope.error = "There was a problem!";
});
}).error(function() {
$scope.status= 0;// Hide loading image
$scope.error = "Problem listing Groups";
});
};
相关文章:
- 在我的情况下,如何进行http请求
- 我如何设置HTTP头“;访问控制允许起源”;用于来自thttpd web服务器的HTTP响应
- 为什么我在Cloud9中的http请求总是返回错误
- 为什么我的$http.post返回一个400错误
- Angular没有't在http请求后更新我的对象
- 为什么我的 http 请求不适用于长 JSON 字符串
- 在我的案例中,如何测试http请求
- 当我的HTTP呼叫因互联网访问而失败时,有没有办法发出错误警报
- 为什么我的 http://localhost CORS 源不起作用
- 为什么我的范围在 angularjs 和 d3js 上的$http函数中丢失了
- 如何在我的基于ajax html5的网站模板 http://www.musicep.com/ 上插入广告?我尝试了一切,
- 如何解决我的http请求问题
- 如何解决我的http请求问题
- 我的HTTP over AJAX(javascript)有什么问题
- 如何防止DOS攻击我的http服务器写在node.js
- 如何显示叠加加载gif,同时完成我的http.Post in angular
- ' '预先挂载到我的HTTP (AJAX) responseText
- Ionic:为什么不是't我的HTTP.GET没有加载我的图像
- 为什么我在Chrome中看不到我的HTTP头
- 在NodeJs中,我怎么能等到我的http get完成