gpt4 book ai didi

javascript - $http.post -> start (用于预加载器)

转载 作者:行者123 更新时间:2023-12-03 08:48:33 25 4
gpt4 key购买 nike

在我的 Controller 中,我现在有:

$http.post('/api/agendainsert', { appointment_datetime: appointment_date + appointment_hour, profile: profile, column_id: column_id })
.success(function(data, status, headers, config){
$state.go('form.success');
})
.error(function(data, status, headers, config) {
console.log("Data: " + data +
"<hr />status: " + status +
"<hr />headers: " + headers +
"<hr />config: " + config);
});
};

$http.postSTARTS时,我可以使用什么功能吗?因此,我可以在屏幕上显示预加载器,并在成功提取数据后隐藏它。

最佳答案

您将需要一个服务来执行此操作。考虑创建一个 WaitService 。 WaitService 将监听两个事件 wait:startwait:stop .

何时 wait:start你必须使用指令在 <body> 上注入(inject)加载动画。当wait:stop那么你必须删除那个加载动画。您可以在 $rootScope 中观看这些事件.

现在包括这个WaitService在您的应用程序中并像这样使用。

$scope.$emit('wait:start'); //indicate start loading
$http.post('/api/agendainsert', { appointment_datetime: appointment_date + appointment_hour, profile: profile, column_id: column_id })
.success(function(data, status, headers, config){
$scope.$emit('wait:stop'); //indicate remove loading
$state.go('form.success');
})
.error(function(data, status, headers, config) {
$scope.$emit('wait:stop'); //indicate remove loading
console.log("Data: " + data +
"<hr />status: " + status +
"<hr />headers: " + headers +
"<hr />config: " + config);
});
};

关于javascript - $http.post -> start (用于预加载器),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32776769/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com