A Simple Ionic Image Cache for all types of images with preview modal
npm install ionic3-image-cacheIonic Module that loads images in a background thread and caches them for later use. Uses FileTransfer from cordova-plugin-filetransfer, and cordova-plugin-file via ionic-native wrappers. This module helps to save Http requests to the server all the time thereby saving bandwidth and other HTTP related issues.
!Gif
#### 1. Install the NPM Package
```
npm install --save ionic3-image-cache
#### 2. Install Required Plugins and Dependency
``
npm i --save @ionic-native/file
ionic cordova plugin add cordova-plugin-file``
npm install --save @ionic-native/file-transfer
ionic cordova plugin add cordova-plugin-file-transfer
``
npm install --save ionic-img-viewer
#### 3. Import IonicImageCacheModule module
Add IonicImageCacheModule.forRoot() in your app's root module
`typescript
import {IonicImageCacheModule} from 'ionic3-image-cache';
// import the module
@NgModule({
...
imports: [
IonicImageCacheModule.forRoot()
]
})
export class AppModule {}
`
html
`You can also listen to the load event to be notified when the image has been loaded:
`html
`...
onImageLoad(data) {
// do something with the loader
}
`HTML attributes
The component takes many attributes that allows you to customize the image. You can use the following table as a reference:
``| Attribute Name | Type | Description | Default Value |
| --- | --- | --- | --- |
| src | string | The image URL | N/A |
| isAvatar | boolean | Sets an avatar image as a placeholder rather than image placeholder | false |
| showPreview | boolean | Displays a full screen version of the image with gestures. | true |
| imgCssClass | string | You can inject css classes to the image | N/A |
| highResSrc | string | Set a highres image to use for image preview on click when showPreview is set to true | Original Src |
| fallbackUrl | string | Sets a custom placeholder image Url while awaiting cache load | N/A |
| spinnerName | string | Set a spinner name from the list of ionic spinners list | dots |
| spinnerColor | string | Set a spinner color from your variable set at variables.scss e.g primary | Default |
| alt | string | Sets an alternative text when image fails on browser | N/A |
| enableSpinner | boolean | Enable or disable spinner | true |
Note: Upcoming features. Please contribute your features.
- Typescript options from controller
- Clear cache
- Max cache settings
- Cache lifespan