I've been successfully loading images using ajax
with the following code. However, when trying to convert it into Angular and use $http
, it's not working as expected.
Original ajax code
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();
Angular Code Attempt
$http.get(attr.imageUrl, {}, {
responseType: 'arraybuffer'
})
.success(function(response) {
var file = new Blob([response]);
element[0].src = URL.createObjectURL(file);
});