Answer the question
In order to leave comments, you need to log in
Why does Resolve return an empty Promise?
Piece from Factory
order.getOrder = function(id) {
var deferred = $q.defer();
$http.get('/order-info/id' + id).success(function(order) {
deferred.resolve(order);
}).error(function(data, status, headers, config) {
deferred.reject(status);
});
console.log(deferred.promise);
return deferred.promise;
};
.state('order', {
url: "/order/id{id}",
views: {
'content': {
templateUrl: "/modules/order/order_details.html",
controller: "orderCtrl",
resolve: {
orderService: 'orderService',
order: ['$stateParams', 'orderService', function($stateParams, orderService) {
var orderId = $stateParams.id;
return orderService.getOrder(orderId);
}]
}
},
}
})
Answer the question
In order to leave comments, you need to log in
The problem is that you need to understand a little more about promises in angular
then always returns a new promise
Let's look at an example:
function asyncFunction() {
var deferred = $q.defer();
doSomethingAsync().then(function(res) {
res = asyncManipulate(res);
deferred.resolve(res);
}, function(err) {
deferred.reject(err);
});
return deferred.promise;
}
function asyncFunction() {
return doSomethingAsync().then(function(res) {
return asyncManipulate(res);
});
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question