0

I want to create a global variable (httpTimeout) initialize at the start, contains a Long value returned by a synchrone call Rest Service and used it in different service

(
 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 i can retrieve this value globally (httpTimeout) for use in other services Thank you for your help

DevJava
  • 31
  • 4
  • Hello, if your question is how to do something on application start : [look at that](https://stackoverflow.com/questions/19276095/execute-code-at-startup-of-angular-application) After your application start you can use another service to store the value. – Ruokki Jun 29 '20 at 20:40

1 Answers1

0

if your question is how to do something on application start : look at that

After your application start you can use another service to store the value.

Also if you want to apply this comportement for all request take a look to interceptor

Ruokki
  • 466
  • 1
  • 2
  • 10