I built a service, that gets a specific ID from an API observable. The service is working, if i console.log(data) from the service class, but i can't get the data in my component.
Service:
getSpecificStory(storyId) {
return this.getToken()
.map(idToken => {
let headers = new Headers();
headers.set('user_token', idToken)
return this.http
.get(`${this.apiUrl}/stories/${storyId}`, { headers: headers })
.subscribe((res: Response) => {
const data = res.json();
console.log(data)
return data;
});
})
.catch(this.handleError);
}
Component:
export class StoryModalComponent implements OnInit {
story: any;
storyId: any;
hitsArray: Array<Object>;
constructor(private storiesService: StoriesService, private route: ActivatedRoute) {
}
ngOnInit() {
this.route.params
.subscribe(
params => {
this.storyId = params['storyId']
})
console.log(this.storyId)
this.getStoryObject();
}
getStoryObject() {
console.log(this.storyId)
this.storiesService.getSpecificStory(this.storyId)
.subscribe(
(data) => {
this.story = data;
console.log(this.story)
})
}
}
