イオン2アプリケーションを作成していて、画像をキャッシュします。 - ImgCache.isCached
コールバックがある https://gist.github.com/ozexpert/d95677e1fe044e6173ef59840c9c484eイオン2キャッシング画像
https://github.com/chrisben/imgcache.js/blob/master/js/imgcache.js
私は与えられたソリューションを実現し、私は予想通りImgCacheモジュールが動作しないことを参照してください。長い間、私はこれらの文献が見つかったウェブ上で検索した後
決して呼び出されません。
ionic 2でイメージをキャッシュするためのアイデアやその他の優れたソリューションはありますか?
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で:
======== UPDATE ==========ここ
は、私が使用するディレクティブのコードです私が行います
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