I have an Angular route which uses a parameter :client_name
, and a service with method getClientDetails(client_name)
to fetch data from an HTTP API based on :client_name
. Both are Observable methods working on their own, but when I combine the 2 observables then the API call runs before the params has been fetched (client_name is undefined):
this.route.params.subscribe(params => {
this.client_name = params['client_name'];
this.dataService.getClientDetails(this.client_name).subscribe(
clientdata => {
this.client = clientdata;
console.log(clientdata);
});
How can I chain both observables so the API only runs once the :client_name
is returned?
getClientDetails
method will only run ifparams['client_name']
is defined? – wentjun