
Security News
Insecure Agents Podcast: Certified Patches, Supply Chain Security, and AI Agents
Socket CEO Feross Aboukhadijeh joins Insecure Agents to discuss CVE remediation and why supply chain attacks require a different security approach.
ng-imgcache
Advanced tools
Angular 2+ / Ionic 2+ module to cache images for offline use.
Important Note: this module supports Angular / Ionic versions 2 and above only. For Angular 1.x / Ionic 1.x, consider angular-imgcache.js, which this module was inspired by.
npm install ng-imgcache
1. Install Cordova plugins:
cordova plugin add cordova-plugin-file cordova-plugin-file-transfer
2. Import the ImgCacheModule:
//app.module.ts
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { ImgCacheModule } from 'ng-imgcache';
import { AppComponent } from './app.component';
@NgModule({
imports: [
BrowserModule,
FormsModule,
ImgCacheModule
],
declarations: [
AppComponent
],
bootstrap: [ AppComponent ]
})
export class AppModule {}
3. Initialise the cache in your AppComponent:
// app.component.ts
import { Component } from '@angular/core';
import { Platform } from 'ionic-angular';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';
import { ImgCacheService } from 'ng-imgcache';
import { HomePage } from '../pages/home/home';
@Component({
templateUrl: 'app.html'
})
export class MyApp {
rootPage:any = HomePage;
constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen, imgCache: ImgCacheService) {
platform.ready().then(() => {
// Okay, so the platform is ready and our plugins are available.
// Here you can do any higher level native things you might need.
statusBar.styleDefault();
splashScreen.hide();
// Ensure you init once the platform is ready.
imgCache.init({
// Pass any options here...
});
});
}
}
4. Use the directive in your component templates:
import { Component } from '@angular/core';
@Component({
selector: 'my-app',
template: `
<img img-cache img-cache-src="http://placekitten.com/200/300">
<div img-cache img-cache-bg-url="http://placekitten.com/200/300"></div>
`,
styles: [`
div, img {
height: 200px;
}
`]
})
export class AppComponent {};
That's it!
TBC: a very similar process to above.
Image URLs that are specified in a img-cache-src or img-cache-bg-url attribute will be downloaded and cached for subsequent offline use by the included imgcache.js library.
Tip: make sure you use img-cache-src with <img> tags, as this will set the src attribute of the <img> tag to the cached image. For other elements, you can use the img-cache-bg-url attribute, which will set the background-image style of the element to point to the cached image.
MIT
Inspired by angular-imgcache.js, this module was rewritten to support Angular 2+ and Ionic 2+ projects. Uses the excellent imgcache.js library.
FAQs
Angular 2+ module to cache images for offline use.
We found that ng-imgcache demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket CEO Feross Aboukhadijeh joins Insecure Agents to discuss CVE remediation and why supply chain attacks require a different security approach.

Security News
Tailwind Labs laid off 75% of its engineering team after revenue dropped 80%, as LLMs redirect traffic away from documentation where developers discover paid products.

Security News
The planned feature introduces a review step before releases go live, following the Shai-Hulud attacks and a rocky migration off classic tokens that disrupted maintainer workflows.