Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

How to get base URL and port in client? #8641


User avatar
0
TimMackey created

service-proxies.ts uses this trick:

    constructor(@Inject(HttpClient) http: HttpClient, @Optional() @Inject(API_BASE_URL) baseUrl?: string) {
        this.http = http;
        this.baseUrl = baseUrl ? baseUrl : "";
    }

I also copied this code (and supporting code):

    providers: [
        { provide: API_BASE_URL, useFactory: getRemoteServiceBaseUrl },

from root.module.ts to main.module.ts

When I use the same code in my app, baseUrl is always null. What might I have missed?


1 Answer(s)
  • User Avatar
    0
    TimMackey created

    I answer my own question.

    Use AppConsts.remoteServiceBaseUrl directly in .ts code.