我是离子框架和承诺的新手,这是我工厂的一部分,Productos
...
getCombinations: function(productId) {
var promises = [];
// todo: quizas filtrar por actividad
url_to = 'http://example.com/api/combinations?display=full&filter[id_product]=' + productId;
$http({method: 'GET', url: url_to })
.then(function(response) {
results = x2js.xml_str2json(response.data);
angular.forEach(results.prestashop.combinations.combination, function(val, key) {
var deferred = $q.defer();
console.log('first deferred');
console.log(deferred);
url_to = 'http://example.com/api/product_option_values?display=[name,color]' + '&filter[id]=[' + val.associations.product_op
tion_values.product_option_value[0].id + '|' + val.associations.product_option_values.product_option_value[1].id + ']';
$http({method: 'GET', url: url_to }).then(function(response) {
results = x2js.xml_str2json(response.data);
resultt = {'size': results.prestashop.product_option_values.product_option_value[0].name.language.__cda
ta, 'color_hex':results.prestashop.product_option_values.product_option_value[1].color.__cdata, 'color_name': results.prestashop.product_option_values.product_option_value[1].name.language.__cdata};
deferred.resolve(resultt);
})
promises.push(deferred);
console.log('pushed');
console.log(promises);
});
}, function(response) {
return $q.reject(response.data);
//algo fue mal
});
return $q.all(promises);
},
...
并在我的控制器中
...
Productos.getCombinations(productId)
.then(function(data) {
console.log('getcombinations');
console.log(data);
...
但是我的数据是空的,有人可以帮助我,提前谢谢。