From 076fa6931f643343df61fefcdd91381eab1e884a Mon Sep 17 00:00:00 2001 From: Richard Park Date: Fri, 18 Oct 2019 09:12:19 +0900 Subject: [PATCH] image loading is modified --- .../src/lib/components/image.component.ts | 33 ++++++++++--------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/projects/ucap-webmessenger-ui/src/lib/components/image.component.ts b/projects/ucap-webmessenger-ui/src/lib/components/image.component.ts index 20834c2a..e9292b9e 100644 --- a/projects/ucap-webmessenger-ui/src/lib/components/image.component.ts +++ b/projects/ucap-webmessenger-ui/src/lib/components/image.component.ts @@ -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; } } }