ConfigModule.withConfig or provideConfig in Spartacus

Viewed 241
2 Answers

As mentioned in the docs, they are the same.

ConfigModule.withConfig({}) behaves the same way as provideConfig({})

The difference between them is that the first is used to be used in import's array, whereas the latter is used in the provider's array

However, you can create an issue in the Spartacus repository https://github.com/SAP/spartacus/issues in order to open the discussion of deprecating ConfigModule.withConfig

'legacy' way

@NgModule({
  imports: [ConfigModule.withConfig({...})],
  providers: [...]
  ...
})
...

'preferred' way

@NgModule({
  imports: [...],
  providers: [provideConfig({...})]
  ...
})

Full examples:

old:

import {CmsConfig, ConfigModule} from "@spartacus/core";

@NgModule({
  imports: [
    CommonModule,
    ConfigModule.withConfig({
      cmsComponents:{
        YourCustomComponentFlexType: {
          component: YourCustomComponent
        }
      }
    } as CmsConfig),
  ],
})

or preferred one:

import {provideConfig} from "@spartacus/core";

@NgModule({
  imports: [
    CommonModule
  ],
  providers: [
    provideConfig({
      cmsComponents: {
        YourCustomComponentFlexType: {
          component: YourCustomComponent
        }
      }
    }),
  ]
})
Related