The scenario is , there is a single service(json-data-service.ts) having a method getWebservicedata() which returns http.post(url) ie it makes an ajax call when method is called. I have different components like(pie-chart-components,bar-chart-component, line-chart components etc) and they all created at the same time on a single page. They all have their different metadata(clientJson) and a single observable.
Is there any way, by which we can make a single ajax request by multiple components parallely.
In other words, is there any way such that before ajax request is executed, it takes all the metadata from different components(PieComponent.ts,LineComponent.ts etc) and fetch data from the same url for different metadata(clientJson) of different components, at the same time parallely?
json-data-service.ts
getSolrData(clientJson): Observable<JsonData[]> {
console.log('Retriving Data from Solr Server.......' + JSON.stringify(clientJson));
let headers = new Headers({ 'Content-Type': 'application/json' });
let options = new RequestOptions({ headers: headers });
let url = "http://183.82./PI3_Sor_WebSer/solrSe";
return this.http.post(url, clientJson).map((res: Response) => res.json());
}
pie-chart.component.ts
initData() {
let clientJson = {
"aoId": "M_AO_918","viewBys": ["usstate"]----------------- };
this.jsonDataService.getSolrData(clientJson).subscribe(
success => this.buildPieChart(success),
error => this.errorMessage = error
);
}
buildPieChart(jsonData) {
-----------
}
line-chart.component.ts
initData() {
let clientJson = {
"aoId": "M_AO_918","viewBys": ["brands"]----------------- };
this.jsonDataService.getSolrData(clientJson).subscribe(
success => this.buildlineChart(success),
error => this.errorMessage = error
);
}
buildlineChart(jsonData) {
-----------
}