I have a service call from my component which gets the list of heroes.from that function where it calls another function which has the http request...How can i subscribe to the function call so that i will get the response properly...Here is my plunker demo http://plnkr.co/edit/UM9STMwaOsgolhBjADjx?p=preview ... This is how i am calling the service from my component
ngOnInit() {
this.heroService.getHeroes()
.subscribe(
heroes => this.heroes = heroes,
error => this.errorMessage = <any>error);
}
And in my Service class i have called this method which calls another method which has http request and subscribed to that...
getHeroes (){
return this.GetListOfHeroes()
.subscribe((data: any) => {
return data;
}
);
}
And finally this is the method which gets the list...
GetListOfHeroes(){
return this.http.get(this.heroesUrl)
.map(this.extractData)
.catch(this.handleError);
}
If i directly call GetListOfHeroes() method from my component it works fine but if i try to call that from another method it shows this error this.heroService.getHeroes(...).subscribe is not a function
Somebody please tell me where i am doing wrong...Thanks