Imagine an Angular Service that encapsulates the HTTP Client Module.
export class HttpWrapperService {
private apiKey: string;
}
Of course, it offers additional features that are not relevant here.
Now I'm faced with the task of supplying HttpWrapperService to multiple modules with a unique default value. This default value should be assigned to a private member variable, namely private apiKey: string;
Thoughts:
Upon observing other imports with default values, I ponder on how this can be achieved.
RouterModule.forRoot(AppRoutes),
GravatarModule.forRoot(GRAVATAR_CONFIG_TYPE1),
AngularFireModule.initializeApp(environment.firebaseConfig),
ServiceWorkerModule.register("ngsw-worker.js", {
enabled: environment.production
})
Current Approach
At present, I am utilizing a static method to initialize a static variable. Yet, unsure if this is the best solution to the issue at hand.
export class AppModule {
constructor(){
HttpWrapperService.register(environment.apiKeyHeaders);
UserService.registerEndpoint(environment.apiEndpoint);
}
}