Skip to content

Commit

Permalink
fix(): use fallback image if image fails to load (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
guillenotfound authored and ihadeed committed Nov 23, 2016
1 parent e2616c3 commit d57f395
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/components/img-loader/img-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ export class ImgLoader implements OnInit {
}

this.imageLoader.getImagePath(this.imageUrl)
.then((imageUrl: string) => this.setImage(imageUrl));
.then((imageUrl: string) => this.setImage(imageUrl))
.catch((error: any) => this.setImage(this.fallbackUrl || this.imageUrl));
}

private setImage(imageUrl: string): void {
Expand Down Expand Up @@ -159,7 +160,7 @@ export class ImgLoader implements OnInit {
this.renderer.setElementStyle(element, 'background-repeat', this.backgroundRepeat);
}

this.renderer.setElementStyle(element, 'background-image', 'url(\'' + imageUrl +'\')');
this.renderer.setElementStyle(element, 'background-image', 'url(\'' + imageUrl + '\')');
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/providers/image-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class ImageLoader {
* @returns {Promise<string>} Returns a promise that will always resolve with an image URL
*/
getImagePath(imageUrl: string): Promise<string> {
return new Promise<string>((resolve) => {
return new Promise<string>((resolve, reject) => {

let getImage = () => {
this.getCachedImagePath(imageUrl)
Expand All @@ -67,7 +67,7 @@ export class ImageLoader {
resolve(localPath);
})
.catch((e) => {
resolve(imageUrl);
reject();
this.throwError(e);
});
});
Expand Down

0 comments on commit d57f395

Please sign in to comment.