title: How to set a timeout to abort an $http.get() inside a factory or service?
body: <p>I have the following method <code>getData(url)</code> in a my <strong>factory</strong> which uses    <code>$http.get(url)</code> to get data from an URL</p>
  
  <pre><code>angular
    .module('az-app')
    .factory('WebServiceFactory', function ($http, $q) {
  
     var WebServiceFactory = this;
  
  
     WebServiceFactory.getData = function (url) {
  
        var deferred = $q.defer();
  
        $http.get(url)
          .then(
          function (response) {
  
            deferred.resolve({
              data: response
            });
  
          }, function (rejected) {
  
            deferred.reject({
              data: rejected
            });
          }
        );
        //Promise to be returned
        return deferred.promise;
      }
  </code></pre>
  
  <p>It works fine but I need to abort the http.get and/or reject the promise so I can display an error message from my <strong>controller</strong> which has this method:</p>
  
  <pre><code>var getSpecialties = function (type) {
    doctorsCtrl.showLoading();
  
    var url = "example.com";
  
    WebServiceFactory.getData(url)
      .then(
      function (result) {
        doctorsCtrl.hideLoading();
  
  
        var specialtiesArray = result.data.data;
  
        StorageFactory.specialties = specialtiesArray;
        doctorsCtrl.specialties = StorageFactory.specialties
  
        //I WANT TO TRIGGER THIS REJECTED FUNCTION when timeout time is finished
      }, function (rejected) {
        doctorsCtrl.hideLoading();
        doctorsCtrl.showAlert();
      }
    );
  }
  </code></pre>