I have the following method in a controller:
$scope.showProductDetails = function (size,product) {
$scope.showLoader('Loading the details of the product. Please wait...');
var modalInstance = $modal.open({
templateUrl: 'productDetail.html',
controller: 'ProductDetailController',
size: size,
resolve:{
productDetails: function (){return productsFactoryHelper.ProductDetail.query({productid:product.id},function()
{
$scope.hideLoader();
},function(error)
{
commonFactory.Pop('error','This product is not available at this moment. Please try again later. If the problem persists contact a system administrator');
$scope.hideLoader();
});}
}
});
};
As you can see, I'm opening a modal panel, and using 'resolve' to pass an object that I retrieve from the server. This call to the server can launch an exception, so I manage this case in the callback function for error, but I cannot avoid the modal panel to open if an error happens. I would like to know if there is a way to do that without changing the structure of the code. I mean I could achieve that just doing the call out of the resolve, before opening the modal panel, and depending if the call is successful or not , open the modal panel, but I would like to know if there is a way to do it inside the resolve, without changing the structure of the method.
Thanks