In this scenario, I have two services injected and I need to ensure that some data, like a base URL, is passed to the first service so that all subsequent services can access it.
Below is my root component:
export class AppCmp {
constructor (private httpService:HttpService, private SomeService:someService){}
}
Here is the code for the first service, let's say it's a custom HttpService:
@Injectable()
export class HttpService{
BASE_URL:string;
constructor(private http:Http){
}
getAll(){ return this.http.get(this.BASE_URL) }
}
And here is the second service, which will rely on the first one to make an HTTP GET request:
@Injectable()
export class SomeService{
constructor(private httpSerivce:HttpSerivce){
this.httpService.getAll()...
}
}
I want to avoid hard coding the base URL or using local storage, so I have two options: either in the main.ts (bootstrap file) or in the root component if they are separate files.
The key is to make sure the data is available right away and can be passed to or retrieved by the first injected service.
I hope I was able to explain the issue clearly. Thank you!