I have a pretty simple design with my AppModule definition. I had a set of Mocked Services in my providers, which leveraged local data until my endpoints can get resolved. I was slowly migrating them over as the service endpoints are stood up. The issue is that the application is very requires some config to get the endpoints up and running, so i created a simple config file which created a property: useMockedServices
for people who want to use a demo.
{
useMockedServices: true
}
BUT, my question is. How do i take this configuration into account for the providers?
...
providers: [
{provide: UserService, useClass: MockUserService},
...
],
...
Could I do something like:
providers: [
{ provide: MAT_DIALOG_DEFAULT_OPTIONS, useValue: { hasBackdrop: false }},
...
].concat( config.useMockedServices ? [
{provide: UserSerice, useValue: MockUserService},
...
]: [],
I tried to do just that but I am getting an error: No Overload matches this call and it says "The Types of property slice are incompatible"
providers: [
// Default Options for using Modals / Dialogs.
{ provide: MAT_DIALOG_DEFAULT_OPTIONS, useValue: { hasBackdrop: false } },
{ provide: HTTP_INTERCEPTORS, useClass: JwtInterceptor, multi: true },
{ provide: HTTP_INTERCEPTORS, useClass: ErrorInterceptor, multi: true },
{ provide: AuthGuard, useClass: AuthGuard },
{ provide: AuthenticationService, useClass: AuthenticationService }
].concat(
configuration.useMockServices === true ? [
{ provide: UserService, useClass: MockUserService },
...
] : []
),
...