【发布时间】:2018-07-04 10:33:41
【问题描述】:
我有一个使用 Angularjs 和 Coldfusion 的应用程序。 我有一个表单,其中包含一些用于填充下拉列表的 http 查询。 当会话服务器退出时,我从服务器检索状态,显示一个对话框(感谢 ngDialog)并重新加载页面。(服务器发送的状态 0,因为服务器在开始之前尝试重新加载外部身份验证系统在应用程序的主页上 - 不在本主题范围内)。
这里我的代码:
app.controller('ctrlAddContacts', function ($scope, $route, ContactService, ngDialog, $timeout){
ContactService.getCountry().success(function(countries){
$scope.countries = countries;
});
ContactService.loadCategory('undefined',0).success(function(categories, status, header, config){
$scope.categories = categories;
console.log("status:" + status);
})
.error(function (data, status, header, config) {
console.log("sessionExpired: " + sessionExpired);
console.log("ERROR ");
console.log("data: " + data);
console.log("status:" + status);
console.log("header: " + header);
console.log("config: " + config);
if (status==0) {
alert("Your session expired - The page needs to be reloaded.\nPlease note that data enter in the form will be lost");
// NGDIALOG BOX
var dialog = ngDialog.open({
template: '<p>Your session expired - The page needs to be reloaded.<br />Please note that data enter in the form will be lost</p>',
plain: true,
closeByDocument: false,
closeByEscape: false
});
setTimeout(function () {
dialog.close();
window.location = "http://myapp/index.cfm?#/add-contacts";
}, 4000);
}
}).finally(function() {
console.log("finally finished repos");
});
});
它正在工作,但我必须为每个 ajax HTTP 请求这样做。
在这里我必须为:
ContactService.getCountry().success(function(countries){
$scope.countries = countries;
});
因此我想简化代码以避免重复该行,您能否告诉我是否可以这样做以及如何做到(例如指令或工厂)?
谢谢
【问题讨论】:
标签: angularjs coldfusion angularjs-http