App module里调用ConfigModule.withConfig注入配置,调用两次withConfig,传入的参数会进行合并:
ConfigModule.withConfig({
cmsComponents: {
SimpleResponsiveBannerComponent: {
component: MycomComponent
},
CartComponent: {
component: MyCartComponent
}
} as CmsConfig
}),
ConfigModule.withConfig({
someCustomComponent: {
a: "b"
}
})
通过构造函数参数注入:
export class AppComponent implements OnInit {
constructor(private componentFactoryResolver: ComponentFactoryResolver,
private outletService: OutletService<ComponentFactory<MycomComponent>>
, @Inject(Config) private config: any) { }
运行时的配置信息:
cmsComponents就是我在app Component里调用withConfig进行的配置:
其中绝大部分属性都是Spartacus的默认配置,只有下图这个是我在代码里更改过的:
这是我传入的另一个自定义配置:
注入时也可以显式地指定配置的类型,比如:
export class AppComponent implements OnInit {
constructor(private componentFactoryResolver: ComponentFactoryResolver,
private outletService: OutletService<ComponentFactory<MycomComponent>>
, @Inject(Config) private config: any,
@Inject(Config) private cmsConfig: CmsConfig) {
debugger;
}
网友评论