The issue mentioned above was successfully resolved by accessing the Azure web app application setting values in a TypeScript file.
To achieve this, I added the following code to Index.cshtml in order to access the app setting values from the web.config file:
<script>
window.config = {
apiBaseUrl: '@System.Configuration.ConfigurationManager.AppSettings["ApiBaseUrl"]',
};
</script>
Subsequently, I included the below code in Services.ts:
import {Injectable, Inject, Optional, OpaqueToken} from '@angular/core';
export const API_BASE_URL = new OpaqueToken('API_BASE_URL');
@Injectable()
export class ApplicationClient {
private baseUrl: string = undefined;
constructor(@Optional() @Inject(API_BASE_URL) baseUrl?: string) {
this.baseUrl = baseUrl ? baseUrl : "";
}
}
Next, I implemented the code below in app.module.ts:
import { ApplicationClient, API_BASE_URL } from './shared/Services';
providers: [{ provide: API_BASE_URL, useValue: window['config']['apiBaseUrl'] }]
Finally, wherever the setting value needs to be accessed, just import the path for Services.ts file in your TypeScript file like so:
import { API_BASE_URL } from '../shared/Services';
@Injectable()
export class writingService {
private _AppUrl = API_BASE_URL+'api/myApplication/';
}
-Pradeep