Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 70612

Using $http.get() in a service - How to use?

$
0
0

@Ionicoser wrote:

Hi all,

while im checking my code i found some difference usings of $http.get() - Whats the correct way?

1:

var getProfiles = function () {
var deferred = $q.defer();
  $http.get(cordova.file.dataDirectory + theFile)
  .success(function(data, status, headers, config) {
    deferred.resolve(data);
  })
  .error(function(data, status, headers, config) {
    deferred.reject({status: "ERROR"});
  });
  return deferred.promise;
}

2:

var getProfiles = function () {
var deferred = $q.defer();
$http.get(cordova.file.dataDirectory + theFile).then(
  function(success) {
    deferred.resolve(success)
  },
  function(error) {
    deferred.reject(error);
  }
);
return deferred.promise;
}

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 70612

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>