在我的 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:start
和wait: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/