javascript - 通过调用 REST 服务初始化全局变量 AngularJS 的问题
问题描述
我想在开始时创建一个全局变量(httpTimeout)初始化,包含一个由同步调用 Rest Service 返回的 Long 值,并在不同的服务中使用它
(
function () {
'use strict';
angular
.module('module')
.factory('MyService', function (
$http,
$q
){
var service = {};
var httpTimeout = function() {
return $http({
method: 'GET', '.../rest/getHttpTimeOut'
}).then(function (response) {
return response.data;
}).catch(function (err) {
return 30000;
});
};
service.myService1= function (Model) {
return $http({
method: 'POST', '..../rest/callRestService1',
data: Model, timeout : httpTimeout
}).then(function (response) {
return response.data;
});
};
service.myService2= function (Model) {
return $http({
method: 'POST', '..../rest/callRestService2',
data: Model, timeout : httpTimeout
}).then(function (response) {
return response.data;
});
};});
我的休息服务
@RequestMapping(value = "/getHttpTimeOut", method = RequestMethod.GET)
@ResponseBody
public long getHttpTimeOutValue() {
return timeoutValue;
}
我如何全局检索此值(httpTimeout)以用于其他服务谢谢您的帮助
解决方案
推荐阅读
- firebase - 为什么在 Cloud Firestore 中没有按顺序添加文档?
- react-native - 功能componentDidMount没有在本机反应中触发
- javascript - 三.js根据坐标定位对象
- python-3.x - 使用来自 datareader 的股票数据时,Pandas 错误“没有要绘制的数字数据”
- php - 第三方调用的 RESTful 端点
- css - 包括对带有 typescript 的样式化组件主题的媒体查询
- r - 如何在R中的字符串集之间找到模式?
- node.js - AWS 转录:如何提供输出文件夹的路径
- django - 如何使用基于类的视图在 Django 中的一个模型的不同模板上显示不同的结果?
- react-native - 在 React Native 上使用 Apple Pay?