Subscribe to it as you would to any other Observable. To obtain parameters from the current URL, subscribe to paramMap of the ActivatedRoute. The following component makes your HTTP request whenever the role ID changes.
Component:
import { ActivatedRoute } from '@angular/router';
export class AppComponent implements OnInit {
constructor(
private dashservice: DashService,
private _route: ActivatedRoute ) { }
}
ngOnInit() {
// get role ID from activated route
this.route.paramMap.subscribe(
(params: ParamMap) => { this.getchartdata(params.get('roleId')); }
);
}
// use roleId 'default' if no parameters are passed
private getchartdata(roleId = 'default') {
this.dashservice.getgraphdata(roleId).subscribe(
response => {
// handle response
},
error => {
// handle error
}
);
}
Also seeing that you don't transform your data in the HTTP call, you could remove .map and return the HTTP response directly.
getgraphdata(defaultroleID): Observable<any> {
return this.apiService.get(WebServiceUrl.dashboard.getPiechartData + '/' + defaultroleID);
}