I am looking to establish a global variable called httpTimeout that will be initialized at the beginning. This variable will contain a Long value retrieved from a synchronous Rest Service call and will be utilized in various services.
(
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;
});
};});
My rest service
@RequestMapping(value = "/getHttpTimeOut", method = RequestMethod.GET)
@ResponseBody
public long getHttpTimeOutValue() {
return timeoutValue;
}
How can I globally access and utilize the value of httpTimeout in other services? Thank you for your assistance.