Skip to content

Instantly share code, notes, and snippets.

@arathunku
Created June 24, 2014 10:43
Show Gist options
  • Save arathunku/211365fb0d1117a240bf to your computer and use it in GitHub Desktop.
Save arathunku/211365fb0d1117a240bf to your computer and use it in GitHub Desktop.
#
# xhr(route) # get - default
# xhr([route]) # get - default
# xhr([route, param, config]) # get - default
# xhr('post', [route, params, config])
# xhr('delete', route, params, config)
#
angular.module('app.services')
.factory 'xhr', ($q, $http) ->
(type, config) ->
if config?
unless angular.isArray(config)
config = Array.prototype.slice.call(arguments, 1);
else
if angular.isArray(type)
config = type
else
config = [type]
type = "get"
deferred = $q.defer()
$http[type].apply($http, config).success((data) ->
deferred.resolve data
).error (reason) ->
deferred.reject reason
deferred.promise
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment