image loading is modified

This commit is contained in:
병준 박 2019-10-18 09:12:19 +09:00
parent d488edd0a4
commit 076fa6931f

View File

@ -66,7 +66,7 @@ export class ImageComponent implements OnInit {
}
baseStyle: SafeStyle;
imageSrc: string | ArrayBuffer;
imageSrc: string;
classList: { [key: string]: boolean } = {};
constructor(
@ -94,22 +94,23 @@ export class ImageComponent implements OnInit {
this.imageSrc = this.default;
const imageUrl = `${this.base}${this.path}`;
this.httpClient
.get(imageUrl, { responseType: 'blob' })
.pipe(take(1))
.subscribe(
blob => {
const reader = new FileReader();
reader.onloadend = ev => {
this.imageSrc = reader.result;
};
reader.readAsDataURL(blob);
},
error => {
this.imageSrc = this.default;
const image = new Image();
image.onload = () => {
if ('naturalHeight' in this) {
if (image.naturalHeight + image.naturalWidth === 0) {
image.onerror('naturalHeight');
return;
}
);
} else if (image.width + image.height === 0) {
image.onerror('width');
return;
}
this.imageSrc = image.src;
};
image.onerror = () => {
this.imageSrc = this.default;
};
image.src = imageUrl;
}
}
}