Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

8
  • Yes, normally the services return observables and in the component we subscribe to this observables. NOTE: If you use httpClient NOT use map(res=>res.json(). You need't do it Commented Aug 16, 2018 at 7:59
  • How do i get the json representation then? otherwise i cant assign the response to my array, right? Commented Aug 16, 2018 at 8:00
  • HttpClient, by defect, give you the json object directly. (use a console.log(res) to check it) Commented Aug 16, 2018 at 8:02
  • 2
    You should also consider using .pipe(takeUntil( /* Subject */)). I usually have a property destroyed$: Subject<void> = new Subject<void>(); and call this.destroyed$.next() in the ngOnDestroy hook. This will stop the subscription once the component is destroyed and will stop any subscription leaking which might affect performance. Commented Aug 16, 2018 at 8:17
  • 1
    @ItFreak yea, you're doing it wrong. Here, you can read more about it in this article. Commented Aug 16, 2018 at 14:10