我正试图通过ajax
通过下面的代码加载图像,它已经在工作。我试图将它转换为角度$http
,它不起作用。
平原Ajax代码
var xhr = new XMLHttpRequest();
xhr.open('GET', attr.imageUrl, true);
xhr.responseType = 'blob';
xhr.onload = function(e) {
element[0].src = window.URL.createObjectURL(this.response);
};
xhr.send();
角码
$http.get(attr.imageUrl, {}, {
responseType: 'arraybuffer'
})
.success(function(response) {
var file = new Blob([response]);
element[0].src = URL.createObjectURL(file);
});
什么是你的'response'对象是什么样子? Angular将响应放在'response.data'中 –
这篇文章可能会有帮助 - https://docs.angularjs.org/api/ng/service/$http – john