Я пишу приложение с ионным 2 и хочу кэшировать изображения.ionic 2 caching images
После долгих поисков в Интернете я нашел эти ссылки: https://gist.github.com/ozexpert/d95677e1fe044e6173ef59840c9c484e
https://github.com/chrisben/imgcache.js/blob/master/js/imgcache.js
Я реализовал данное решение, но я вижу, что модуль ImgCache не так, как ожидалось - ImgCache.isCached
обратного вызова никогда не звонил.
Любая идея или другое хорошее решение для кеширования изображений в ионных 2?
======== UPDATE ==========
Вот код директивы я использую:
import { Directive, ElementRef, Input } from '@angular/core';
import ImgCache from 'imgcache.js';
@Directive({
selector: '[image-cache]'
})
export class ImageCacheDirective {
constructor (
private el: ElementRef
) {
// init
}
ngOnInit() {
// This message is shown in console
console.log('ImageCacheDirective *** ngOnInit: ', this.el.nativeElement.src);
this.el.nativeElement.crossOrigin = "Anonymous"; // CORS enabling
ImgCache.isCached(this.el.nativeElement.src, (path: string, success: any) => {
// These message are never printed
console.log('path - '+ path);
console.log('success - '+ success);
if (success) {
// already cached
console.log('already cached so using cached');
ImgCache.useCachedFile(this.el.nativeElement);
} else {
// not there, need to cache the image
console.log('not there, need to cache the image - ' + this.el.nativeElement.src);
ImgCache.cacheFile(this.el.nativeElement.src,() => {
console.log('cached file');
// ImgCache.useCachedFile(el.nativeElement);
});
}
});
}
}
В app.nodule.es я:
import { ImageCacheDirective } from '../components/image-cache-directive/image-cache-directive';
, а затем в home.html:
<img src="http://localhost/ionic-test/img/timeimg.php" image-cache>
Пожалуйста, добавьте часть своего кода, где вы объявляете/используете модуль – akz92
Я не могу поверить, что кеширование изображений игнорируется ионным сообществом .. – EralpB