1

I created an app and it does work great but images load every time I scroll up and down, I looked it in google and found this, the problem is I use angular, there is no such thing as viewModel in my angular version, how do I apply cache image into template?

1 Answers1

2
You can try this code. It is working for me.

.ts code

 import imageCacheModule = require("ui/image-cache");
 import imageSource = require("image-source");
 var cache = new imageCacheModule.Cache();

 private _imageSrc: any;
 private imgSource: any;


    getImageCache(imageURL) {
        cache.placeholder = imageSource.fromResource("res://no-image.png");
        cache.maxRequests = 10;

        cache.enableDownload()
        var images = cache.get(imageURL)
        if(images) {

           return images
        } else {

            cache.push({
                key: imageURL,
                url: imageURL,
                completed: (image: any, key: string) => {
                    if (imageURL === key) {
                        this.imgSource = imageSource.fromNativeSource(images);
                    }
                }
            })

        cache.disableDownload();
    }

HTMl code

<Image  [src]="getImageCache(item.image?.url)" class="item-image"></Image>
Jay Thakkar
  • 1,392
  • 10
  • 19