title: AngularJS http return value
body: <p>I want to write a function in AngularJS that returns a value (actually it is a string). That value is returned by a http request, but async is driving me crazy.</p>
  
  <p>My first attempt was:</p>
  
  <pre><code>this.readParameter = function(key) {
    $http({
      method: "GET",
      url: "XXXXXXX",
      headers: { 'Content-Type': 'application/json' }
    }).then(function successCallback(response) {
      return response.data;
    }, function errorCallback(response) {
      throw new Error("Error");
    })
  };
  </code></pre>
  
  <p>But of course it does not work because of Angular async features (response.data is undefined)</p>
  
  <p>What is the way to do it? I just want to return the value (string), so I can use this function like </p>
  
  <pre><code>var a = readParameter("key1")
  </code></pre>