我正在AngularJS中创建一个注册表单,一旦管理员填写表单并提交,我将做两件事:1。将数据保存到数据库中。2.用用户名和密码给对方发送电子邮件。因此,在提交申请时,我需要一些时间(大约5-7秒(才能在屏幕上发布成功消息。因此,我想在这些后台操作完成时显示一些信息。我刚接触AngularJS,需要你的帮助。
createUserService.Register(obj, function(data) {
if (data.error) {
console.log("Check " + data.error);
} else {
alertify.alert("Successfully Registered");
$state.reload();
}
这是我的服务:
function Register(obj, callback) {
$http({
method : 'POST',
url : '/api/addUserOps',
data : obj
}).then(function(response) {
callback(response.data);
}, function(error) {
callback(error);
});
}
});
您可以尝试这种方式。
服务功能
function Register(obj) {
return $http({
method : 'POST',
url : '/api/addUserOps',
data : obj
});
}
调用您的函数
// Trying using https://github.com/cgross/angular-busy for showing a loader here.
createUserService.Register(obj)
.then(function(data){
// stop your loader here with a success message.
})
.catch(function(error) {
// your error message here.
})
希望你觉得这个有用。