I'm working with an Asp.Net Core 3 web application implementing an Angular 9 application. And I'm needing to pass a Url (host for the web api) found in the config file to the angular application. What is the best way to do this? One thing I thought of was to use an MVC page to write the value in a hidden input field, but I'm not sure if that is best practice. Thanks for the help.
Asked
Active
Viewed 69 times
1 Answers
0
My recommendation is the following, if you have the config file is a json you can make a get to it using the HTTPClient library of angular, after capturing the data you want you can create an Observer, BehaviorSubject, or whatever you feel more comfortable, in which you set the variable where you store the url, that way you can have the url accessible throughout the application
for example create service to get configFile
@Injectable({providedIn: 'root'})
export class ConfigLoaderService{
constructor(private http: HttpClient) {}
getConfigFile(): Observable<HttpResponse<any>> {
return this.http.get<any>(`` + '/asset/config.json', { observe: 'response'});
}
}
then yo can use this class in injecting in constructor
Hope help you, Regards

Jorge Dieguez Perez
- 187
- 8