I have a CoreModule
(which provides common functionalities like providing customised wrapper service on top of HttpClient
etc. - as npm package), and AppModule
(Angular application which installs CoreModule
as npm package).
CoreModule
has many things regarding configuration (i.e. login URL, base URL for REST endpoints
, etc.). So whenever I need to fetch data from the server, I just give endpoint URL
to the services exposed by CoreModule
and then it takes care of rest of the things like creating complete request URL, making ajax call, providing response, etc.
Now, is there any way so that I can update (override) the base URL
(of CoreModule
) from my AppModule
?
In Angular 1.x, we used to have value
recipe. So, we could do like
angular.module('myApp').config(['$provide', function($provider){
$provider.decorator('configVarsInCoreModule', ['$delegate', function($delegate){
// give configParamFromClientApp
angular.extend($delegate, configParamFromClientApp);
}]);
}]);
Is there any similar (or different) way available in Angular 4+ to achieve similar kind of behaviour?
The thing is, once I update/override the baseURL
(or any other config variable) from client app, it should be updated for the CoreModule
as well. So if any other service/component tries to access the variable (even from CoreModule
), it should read the updated value.