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

1
  • Hello, 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. Commented Jun 29, 2020 at 20:40

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.