When I try to import test from ConfigAppProviderModule, I'm getting the error of "has no exported member test". Is I'm making any mistake in writing service with config in module.
import { NgModule ,InjectionToken,Injectable } from '@angular/core';
export const ConfigToken = new InjectionToken<string>('ConfigToken');
class test {
config:any;
constructor(config){
this.config = config;
}
a(){
console.log("this.config",this.config);
}
}
const ConfigAppProvider = {
provide: test,
useFactory: (config) => {
return new test(config);
},
deps: [ ConfigToken]
};
@NgModule({
providers: [ ConfigAppProvider ],
})
export class ConfigAppProviderModule {
static initializeApp(config) {
return {
ngModule: ConfigAppProviderModule,
providers: [
{ provide: ConfigToken, useValue: config }
]
}
}
}
You did not export the const ConfigAppProvider
export const ConfigAppProvider = {
provide: test,
useFactory: (config) => {
return new test(config);
},
deps: [ CsbaseAppConfigToken ]
};
Similarly
export class Test
and also you are not decorating it with @Injectable()
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.