我设置了一个Plunker,因为我试图通过$ http调用检索外部图像并在成功检索或状态200时返回URL并且如果404或错误
http://plnkr.co/edit/ythKksFLWYA30laMGF1g?p=preview
angular.module('testApp')
.factory('ProductImageFactory', function(config, $q, $http, $log) {
return {
getProductImg: function() {
var deferred = $q.defer();
$http.jsonp(config.LINK)
.success(function(data) {
deferred.resolve({
console.log('return LINK');
});
}).error(function() {
deferred.reject();
console.log('Placeholder: Image not available')
});
return deferred.promise;
}
};
});