How would I return a promise but invoke its failure block immediately? Here's a gnarly way to do it:
if (fail) {
var q = $q.deferred();
$timeout(function() {
q.reject("")
}, 1);
return q.promise;
} else {
return $http.get("/").then(function(data) {});
}
function setLike(productId){
return new Promise(function(succeed, fail) {
if(!productId) throw new Error();
jQuery.ajax({
success: function (res) {
succeed(res)
}
})
})
}
setLike(id).then(function(){
//render
}).catch(function(e){})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With