# Need some help with HttpClient / map

**URL:** <https://forum.ionicframework.com/t/need-some-help-with-httpclient-map/116843>\
**Category:** ionic-v3\
**Created:** [December 30, 2017, 3:52pm UTC](https://forum.ionicframework.com/t/need-some-help-with-httpclient-map/116843 "2017-12-30T15:52:36Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![johnmccallister](https://avatars.discourse-cdn.com/v4/letter/j/13edae/32.png) [@johnmccallister](https://forum.ionicframework.com/u/johnmccallister)\
**Post date:** [December 30, 2017, 3:52pm UTC](https://forum.ionicframework.com/t/need-some-help-with-httpclient-map/116843/1 "2017-12-30T15:52:36Z")

</div>

```auto
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/catch';
import 'rxjs/add/operator/map';

@Injectable()
export class RestProvider {

  baseUrl:string = "https://localhost.local/api/v1";

  constructor(private httpClient: HttpClient) {}
    
  //Get latest events from API
  public getEvents(): Observable<Event[]> {
    return this.httpClient
      .get(this.baseUrl + '/events')
      .map(events => {
        return events.map((event) => new Event(event));
      })
      .catch((err)=>{
          console.error(err);
          return Observable.throw(err);
      });
  }

  public getEventById(eventId: number): Observable<Event> {
    return this.httpClient
      .get(this.baseUrl + '/events/' + eventId)
      .map(response => {
          return new Event(response);
      })
      .catch((err)=>{
          console.error(err);
          return Observable.throw(err);
      });
  }  
}

export class Event {
  id: number;
  calendar_id: number;
  title: string;
  slug: string;
  excerpt: string;
  content: string;
  multidate: string;
  allday: number;
  grouped: number;
  event_gty: number;
  event_price: number;
  location_name: string;
  location_address: string;
  contact_email: string;
  constructor(values: Object = {}) {
       Object.assign(this, values);
  }
}

```

return events.map((event) =\> new Event(event));

map has a TS error "Property ‘map’ does not exist on type ‘object’.

I’m sure this is a complete newb question, so any help is greatly appreciated!

---

<div class="post-metadata">

**Author:** ![reedrichards](https://avatars.discourse-cdn.com/v4/letter/r/34f0e0/32.png) [@reedrichards](https://forum.ionicframework.com/u/reedrichards)\
**Post date:** [December 30, 2017, 4:56pm UTC](https://forum.ionicframework.com/t/need-some-help-with-httpclient-map/116843/2 "2017-12-30T16:56:57Z")

</div>

No `.map` needed with the “new” HttpClientModule, remove it

Check my following answer there, this simple query works for me in prod

[https://forum.ionicframework.com/t/ionic-with-angular-5-and-new-httpclient/116846/2?u=reedrichards&source\_topic\_id=116843](https://forum.ionicframework.com/t/ionic-with-angular-5-and-new-httpclient/116846/2?u=reedrichards&source_topic_id=116843)

P.S.: If you want to return a observable you could to

```
public getEvents(): Observable<Object> {
   return this.httpClient.get(this.baseUrl + '/events');
}
```

---

<div class="post-metadata">

**Author:** ![johnmccallister](https://avatars.discourse-cdn.com/v4/letter/j/13edae/32.png) [@johnmccallister](https://forum.ionicframework.com/u/johnmccallister)\
**Post date:** [December 30, 2017, 5:49pm UTC](https://forum.ionicframework.com/t/need-some-help-with-httpclient-map/116843/3 "2017-12-30T17:49:36Z")

</div>

Thank you!

What’s the difference between an observable and subscribe?

---

<div class="post-metadata">

**Author:** ![AaronSterling](https://avatars.discourse-cdn.com/v4/letter/a/51bf81/32.png) [@AaronSterling](https://forum.ionicframework.com/u/AaronSterling)\
**Post date:** [December 30, 2017, 5:58pm UTC](https://forum.ionicframework.com/t/need-some-help-with-httpclient-map/116843/4 "2017-12-30T17:58:00Z")

</div>

An Observable emits a stream. A subscription listens to an Observable.

---

<div class="post-metadata">

**Author:** ![reedrichards](https://avatars.discourse-cdn.com/v4/letter/r/34f0e0/32.png) [@reedrichards](https://forum.ionicframework.com/u/reedrichards)\
**Post date:** [December 30, 2017, 6:01pm UTC](https://forum.ionicframework.com/t/need-some-help-with-httpclient-map/116843/5 "2017-12-30T18:01:06Z")

</div>

You subscribe to an observable 😉

---

<div class="post-metadata">

**Author:** ![johnmccallister](https://avatars.discourse-cdn.com/v4/letter/j/13edae/32.png) [@johnmccallister](https://forum.ionicframework.com/u/johnmccallister)\
**Post date:** [December 30, 2017, 6:22pm UTC](https://forum.ionicframework.com/t/need-some-help-with-httpclient-map/116843/6 "2017-12-30T18:22:07Z")

</div>

Saweeeet!

It worked like a charm too. You are awesomesauce!

---

<div class="post-metadata">

**Author:** ![mhartington](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mhartington/32/137757_2.png) [@mhartington](https://forum.ionicframework.com/u/mhartington)\
**Post date:** [July 19, 2021, 9:57pm UTC](https://forum.ionicframework.com/t/need-some-help-with-httpclient-map/116843/7 "2021-07-19T21:57:17Z")

</div>


