title: Create promise in AngularJS
body: <p>I'm trying to create a promise in Angular with the $q service.
  It returns an object retrieved from a web service. If the object is in the cache, it returns it without calling the web service.</p>
  
  <p>The problem is that the two resolves are getting called. </p>
  
  <p>Maybe, Am I using a promise anti-pattern?</p>
  
  <p>Here is my code:</p>
  
  <pre><code>    function returnMapAsync() {
  
    return $q(function (resolve, reject) {
      if (navigationMap) {
        resolve(navigationMap);
      } else {
        ServerRequest.getNavigationMap().then(function (data) {
          navigationMap = data.object;
          resolve(navigationMap);
        });
      }
    });
  }
  </code></pre>
  
  <p>Thank you</p>