My angular
service is called clientAppSettings.service.ts
. It retrieves configuration values from a json file on the backend named appsettings.json
.
I need to inject this angular service in order to populate the values in the environment.ts
file. Specifically, the instrumentationKey
should be obtained from the service (clientAppSettings.service.ts
). Any assistance would be greatly appreciated.
Below is the content of the environmen.ts
file:
export const environment = {
production: false,
appInsights: {
instrumentationKey: 'some-key'
}
};
The angular service code found in clientAppSettings.service.ts
:
@Injectable()
export class ClientAppSettingService {
appUrl: string = "";
constructor(private http: HttpClient, @Inject('BASE_URL') baseUrl: string) {
this.appUrl = baseUrl;
}
getConfig() {
return this.http.get<ClientAppSettings>(this.appUrl + 'api/ClientAppSettings');
}
}
The backend controller details are as follows:
namespace WebApp.Controllers
{
[Route("api/[controller]")]
public class ClientAppSettingsController : Controller
{
private readonly AppSettings _clientAppSettings;
public ClientAppSettingsController(IOptions<AppSettings> appSettings)
{
_clientAppSettings = appSettings.Value;
}
[HttpGet("[action]")]
public AppSettings Get()
{
return _clientAppSettings;
}
}
}
Lastly, here is the content of the appsetting.json
:
{
"AppConfig": {
"ApplicationInsights": {
"InstrumentationKey": "some-key"
}
}