Dependency injection of modules which are not browser supported


#1

I am using Transfer plugin from ionic-native in my app. I would like to inject it into the app so that testing becomes easier. In app.module.ts

providers: [Transfer]

But Transfer is a cordova plugin which is not browser supported. So this would fail in development and test. So I would like to mock the plugin if it is in browser . Here is a mock on how I would like to implement it.

const TRANSFER_PROVIDER: any;

if (environment.browser) {
  TRANSFER_PROVIDER = Transfer;
} else {
  TRANSFER_PROVIDER = { provide: Transfer, useClass: NativeTransfer }
}

...
providers: [ TRANSFER_PROVIDER ]

But how can I check if its in browser or not in ionic 2 ? Or Is there any other way to implement this logic?