Skip to content

Commit

Permalink
fix(image loader): clear src and srct on changes and pre load image
Browse files Browse the repository at this point in the history
prevents rendered image being reused when inputs change
  • Loading branch information
jackhkmatthews committed May 21, 2018
1 parent bc4bacf commit 9682008
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -218,4 +218,10 @@ describe('ImageLoaderComponent', () => {
component.ngOnChanges();
expect(spy).toHaveBeenCalled();
});

it('should preload image on changes', () => {
const spy = spyOn(component, 'preloadImage');
component.ngOnChanges();
expect(spy).toHaveBeenCalled();
});
});
3 changes: 3 additions & 0 deletions src/app/image-loader/image-loader/image-loader.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,9 @@ export class ImageLoaderComponent implements OnInit, AfterViewInit, OnDestroy, O
* @memberof ImageLoaderComponent
*/
public ngOnChanges(): void {
this.src = '';
this.srcset = '';
this.setPlaceholder();
this.preloadImage();
}
}

0 comments on commit 9682008

Please sign in to comment.