, Angular, , , , .
, , , , , .
function getAllCatalogs() {
return $q.all([
$http.get(baseUrl + 'equipment-design/'),
$http.get(baseUrl + 'engines-design/'),
$http.get(baseUrl + 'suspension-design/'),
$http.get(baseUrl + 'artifacts-design/')
]).then(function (data) {
return data;
});
}
- $q.all , promises , - , , , , , , fail , , , , $http.get , getCatalogPromise, URL- , :
function getCatalogPromise(url) {
var deferred = $q.defer();
$http.get(url).then(function (response) {
deferred.resolve(response)
}, function () {
deferred.resolve([]);
})
return deferred.promise;
}
function getAllCatalogs() {
return $q.all([
getCatalogPromise(baseUrl + 'equipment-design/'),
getCatalogPromise(baseUrl + 'engines-design/'),
getCatalogPromise(baseUrl + 'suspension-design/'),
getCatalogPromise(baseUrl + 'artifacts-design/')
]).then(function (data) {
return data;
});
}
if you pay attention to the getCatalogPromise code , it doesn’t matter what returns the service call, which our deferred will always be in a permission state, and this is what $ q.all , the only difference is that if the service fails, we return empty array.
source
share