提问人:Sharath B 提问时间:4/29/2020 最后编辑:Sharath B 更新时间:4/30/2020 访问量:132
显示 请在 AngularJS 中填写表单后等待或处理给用户的消息
Display Please wait or processing message to user once the form is filled in AngularJS
问:
我正在 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);
});
}
});
答:
0赞
SelftaughtMonk
4/30/2020
#1
你可以试试这种方式。
服务功能
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.
})
希望你觉得这有用。
评论
0赞
Sharath B
4/30/2020
嗨,Shaul,谢谢你的回答。但是,当我按照上面的建议执行相同的操作时,我收到以下错误:TypeError:无法读取未定义的属性“then”
0赞
SelftaughtMonk
4/30/2020
是否在 Register 服务函数中返回$http调用?
评论