I have an Angular component that is effectively showing a list of thumbnail images for a list of video streams:
<div *ngFor="let s of streamList;trackBy: streamListTrackFn">
<div class="thumbnail">
<img [attr.src]="loadThumbnail(s.thumbnailUrl) | async" />
</div>
</div>
Previously I was directly binding [src]="{{s.thumbnailUrl}}"
and as the streamList
got periodically updated, I got a new list of images rendered with fresh thumbnails.
The service providing the thumbnails requires Basic authentication so I am trying to switch to loading the images with my own XHR request, that is why I changed to [attr.src]="loadThumbnail(..)"
which returns an image data URI loaded asynchronously as an `Observable".
My problem is that on the network tab even without changes happening on the streamList
which drives the *ngFor
I am seeing a huge number of HTTP requests being shoot out and also cancelled. I assume this is digest cycle/binding thing in Angular.
What would be the most optimal way to load the thumbnails in this case without falling into this infinite loop of requesting the thumbnails over and over again? (The thumbnailUrl
itself carries a ?t=123456
counter to help mitigating any caching issue)
How can I prevent Angular from doing a new loadThumbnail
until the streamList
really changes..? Or actually at least the s.thumbnailUrl
?
Thanks!