Read an environment variable from a .NET appSettings.json file in an Angular service?

Discussão em 'Angular' iniciado por lschmid, Dezembro 5, 2024.

  1. lschmid

    lschmid Guest

    I have a service which requests some JSON data from a Web API:

    import { Injectable } from '@angular/core';
    import { Http } from '@angular/http';
    import 'rxjs/add/operator/map';

    @Injectable()
    export class ReviewService {
    private actionUrl: string;

    constructor(private _http: Http) {
    this.actionUrl = 'http://api.dc-shop.com/review';
    }

    public GetAll = (): any => {
    return this._http.get(this.actionUrl)
    .map(x => x.json());
    }
    }


    I would like to avoid hard coding the API address in the constructor and instead read a setting from appSettings.json which I can use for the action URL at startup for production and localhost servers.

    What is the best way of doing this in ASP.NET MVC Core?

    Continue reading...

Compartilhe esta Página