@arctican wrote:
Hello.
I’ve created a couple of mock classes for testing in the browser. When testing on a device, I manually remove these from the providers list before the build. I now want to automatically include or remove them based on the
--prod
flag.I have tried various methods, from webpack config, to environment variables, to custom services. In other parts of the app, I use
isDevMode()
as a quick getter to change some variables. The trouble is thatisDevMode()
can’t be called beforeenableProdMode()
which appears to be after the main module is set up.I would like to conditionally add an array of mock providers to the provider list such as:
const mockProviders = [ { provide: Camera, useClass: CameraMock }, { provide: Geolocation, useClass: LocationMock }, ]; @NgModule({ providers: [ commonProviders, isDevMode() ? mockProviders : [] ], ....
Is there a simple way to do this?
Cheers
Posts: 2
Participants: 1