Итак, я бы создал класс расширения Http и обновил конечную точку на основе параметра, отправленного вами через запрос http.
Расширитель Http:
export function HttpAuthCreator(http: HttpClient) {
return new HttpAuth(http)
}
@Injectable()
export class HttpAuth {
// Extending the HttpClient through the Angular DI.
public constructor(public http: HttpClient) {
// If you don't want to use the extended versions in some cases you can access
the public property and use the original one.
// for ex. this.httpClient.http.get(...)
}
/**
* GET request
* @param string endPoint it doesn't need / in front of the end point
* @param IRequestOptions options options of the request like headers, body, etc.
* @returns Observable<T>
*/
public get<T>(endPoint: string, destination?: string, options?: IRequestOptions): Observable<T> {
return this.http.get<T>(
this.updateEndpoint(endPoint, destination),
this.configRequestOptions(options, destination)
)
}
И затемваша подпрограмма для обновления конечной точки
private updateEndpoint(endpoint: string, destination?: string) {
if (destination === 'local') {
return `${environment.localAPI}${endpoint}`
} else {
return `${environment.onlineAPI}${endpoint}`
}
}
Таким образом, вы можете динамически обрабатывать местоположения ваших конечных точек
get() {
return this.http.get(`/organizations/${params.id}`, 'local').toPromise()
}