什么'当从AngularJS中的API响应接收到错误时,触发错误弹出模式的最佳方式
What's the best to way to trigger an error pop up modal when receive an error from API response in AngularJS?
.success(function (data) {
console.log(data);
$http.put("/admin/" + response.data._id + "/facilities", {
update: { $push: { facilities: data.facility._id } }
}).success(function (data) {
$window.location.href='/admin/registrationSuccess';
});
});
}, function (response) {
$scope.list = response.data.error;
});
.form-group.col-lg-7
label(for='username') Username:
input.form-control(type='text', ng-model = 'username', placeholder='Enter Username', required='')
p {{list}}
现在我正在使用角度表达式{{}}来显示错误。但我想在出现包含response.data.error的错误时弹出一个模型。如果服务器发送错误响应,是否可能有一个值为true的模型。无论如何,使用控制器显示错误的最佳方式是什么?
您可以使用angular ui通知来显示通知。下面是Github链接
https://github.com/alexcrack/angular-ui-notification
// Simple PUT request example:
var req = {
method: 'PUT',
url: '/someUrl',
headers: {
'Content-Type': 'application/json'
},
data: { test: 'test' }
}
$http(req).then(function successCallback(response) {
// Here you can process successful response
// Show notification
Notification.success({message: 'Success notification'});
}, function errorCallback(response) {
// Here you can process error
// Show notification
Notification.error({message: 'Error notification'});
});
相关文章:
- 如何以编程方式查找javascript语法错误的位置
- 如何检测以跨浏览器方式使用 Javascript 的 DOMParser 时的 XML 解析错误
- 什么's是在Node.js中公开和组合错误的最佳方式
- 以错误的方式反递减
- 以处理错误的方式启动javascript承诺蓝鸟链
- 你能帮我修复杰弗里方式滑块第一次尝试 imgWidth 错误吗?
- 节点断言错误未打印,断言以静默方式失败
- 以编程方式提交角度表单,但仍会收到 HTML5 验证错误
- 滚动过程中的错误行为,根据代码的链接方式显示
- 以什么方式触发骨干.js错误功能
- 我正在设置计时器,但我以错误的方式进行.所以请给我更好的方法来做到这一点
- 在Angular中显示表单验证错误的正确方式
- 我的查询获胜'因为一个剧本,它不能工作(它以错误的方式工作)!?但为什么呢?SESSIONS和PHP
- 什么'当从AngularJS中的API响应接收到错误时,触发错误弹出模式的最佳方式
- 未捕获的类型错误:无法读取属性'排序方式'的未定义
- Javascript和此错误.取决于函数的调用方式
- Opencart错误“;SyntaxError:意外的标记<"付款方式结账期间
- 检测方式“;拒绝显示文档,因为X-Frame-Options禁止显示"错误
- 如何在Typescript中使用CSSNext并避免讨厌的“;错误TS2349”;Typescript方式
- 使用JQuery以不可见的方式调用URL并返回成功/错误标志