Angular 6 - HttpClient Keeping subscribe in the service but passing the result to the component
问题 I have a preject which contains a service (which gets the data) and a component (displays it). I would like the keep the code to the minimum on the app.component.ts. In the service I have: getPosts() { return this.http.get('https://jsonplaceholder.typicode.com/posts', httpOptions).subscribe( result => { return result; this.theData = result; }, error => { return error; } ); } and in my app.component.ts: getPostsFromService() { this.myService.getPosts(); } But of course, I need to get the