封装自定义服务$http

var httpService = angular.module('httpService', []);

httpService.factory("$httpService",function ($http, $q) {
var $httpService = {};
$httpService.getData = function (url,method,params) {
var defer = $q.defer(),
urls = "http://xxxx.com" + url,
headers = {'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8'};
if (method === 'GET') {
$http({
url: urls,
method: "GET",
headers: headers,
params: params,
}).success(function (data) { defer.resolve(data);
}).
error(function (data, status, headers, config) {
defer.reject(data);
});
} else {
$http({
url: urls,
method: method,
headers: headers,
data: params,
}).success(function (data) {
defer.resolve(data);
}).
error(function (data, status, headers, config) {
// defer.resolve(data);
defer.reject(data);
});
}
return defer.promise;
};
return $httpService;
});
上一篇:MD5加盐 Java加密算法


下一篇:POJ 2728 Desert King 01分数规划,最优比率生成树