From 6881a1fca7828fa99ba2f77ae447ebe2332ab86b Mon Sep 17 00:00:00 2001 From: Ibby Hadeed Date: Tue, 4 Apr 2017 05:01:59 -0400 Subject: [PATCH] feat(): add forRoot method for module --- README.md | 17 ++++++++++++++++- src/image-loader.module.ts | 22 ++++++++++++++-------- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index b41d7cd..436d868 100644 --- a/README.md +++ b/README.md @@ -41,18 +41,33 @@ npm i --save @ionic-native/transfer ionic plugin add cordova-plugin-file-transfer --save ``` -#### 3. Import `IonicImageLoader` module into your app's module. +#### 3. Import `IonicImageLoader` module +**Add `IonicImageLoader.forRoot()` in your app's root module** ```typescript import { IonicImageLoader } from 'ionic-image-loader'; // import the module +@NgModule({ + ... + imports: [ + IonicImageLoader.forRoot() + ] +}) +export class AppModule {} +``` + +Then **add `IonicImageLoader` in your child/shared module(s) +```typescript +import { IonicImageLoader } from 'ionic-image-loader'; + @NgModule({ ... imports: [ IonicImageLoader ] }) +export class SharedModule {} ``` # Usage diff --git a/src/image-loader.module.ts b/src/image-loader.module.ts index 20cb5e7..b50414f 100644 --- a/src/image-loader.module.ts +++ b/src/image-loader.module.ts @@ -1,4 +1,4 @@ -import { NgModule } from '@angular/core'; +import { NgModule, ModuleWithProviders } from '@angular/core'; import { ImgLoader } from './components/img-loader'; import { ImageLoader } from './providers/image-loader'; import { ImageLoaderConfig } from './providers/image-loader-config'; @@ -10,12 +10,6 @@ import { Transfer } from '@ionic-native/transfer'; declarations: [ ImgLoader ], - providers: [ - ImageLoaderConfig, - ImageLoader, - File, - Transfer - ], imports: [ IonicModule ], @@ -23,4 +17,16 @@ import { Transfer } from '@ionic-native/transfer'; ImgLoader ] }) -export class IonicImageLoader {} +export class IonicImageLoader { + static forRoot(): ModuleWithProviders { + return { + ngModule: IonicImageLoader, + providers: [ + ImageLoaderConfig, + ImageLoader, + File, + Transfer + ] + }; + } +}