Ok i have the following code
Load: function (urlInfo, moduleInfo) {
return (function() {
var paramsObj = CheckParams(urlInfo.params);
if (paramsObj != null)
return $http.get(urlInfo.url, { params: paramsObj, cache: $templateCache });
else
return $http.get(urlInfo.url, { cache: $templateCache });
}()).then(this.successFn, this.errorFn);
},
successFn: function (response) {
if (response) {
return response;
} else {
// invalid response
return $q.reject(response);
}
},
errorFn: function (response) {
// something went wrong
return $q.reject(response);
},
I think the above code has problems because it not use the promise and don't use the deferred object and also don't make the resolve of the object and i think the code must be reviewevd like that:
GetData: function (urlInfo) {
return function () {
var deferred = $q.defer();
var paramsObj = CheckParams(urlInfo.params);
if (paramsObj != null){
$http.get(urlInfo.url, { params: paramsObj })
.success(function (data, status, headers, config) {
//resolve the promise
deferred.resolve(data); //#1
})
//if request is not successful
.error(function (data, status, headers, config) {
//reject the promise
deferred.reject('ERROR');
});
}
return deferred.promise;
}()).then(function (resolve) {
return resolve;
}, function (reject) {
return reject;
});
}
because i m not expert you can tell me what are the problems that can come out using the first code (if there are problems)