0

I have setup my application with HTTP_PROVIDERS

bootstrap(AppComponent, [
  HTTP_PROVIDERS,
  ROUTER_PROVIDERS,
  provide(LocationStrategy, { useClass: HashLocationStrategy }),
  PostService
]);

and my service like

@Injectable()
export class PostService {
  posts = [];

  constructor(http: Http) {
    this.http = http;
  }
}

but when i call

this.http.get('/posts')

It returns an Observable which has no map method, it drives me crazy for hours. Im using Babel to transpile my javascript code.

3
  • 2
    They removed most of the operations from the code, you need to import the part of the library that includes that method manually. Try this: import 'rxjs/add/operator/map'; Commented Jan 26, 2016 at 22:51
  • 1
    See this answer: stackoverflow.com/questions/34515173/… Commented Jan 27, 2016 at 6:37
  • @ThierryTemplier, thanks, I closed it as a dup. (I think this question comes up about once a week.) Commented Jan 27, 2016 at 17:04

1 Answer 1

3

The newly minted Server Communication dev guide (finally) discusses/mentions/explains this:

The RxJS library is quite large. Size matters when we build a production application and deploy it to mobile devices. We should include only those features that we actually need.

Accordingly, Angular exposes a stripped down version of Observable in the rxjs/Observable module, a version that lacks almost all operators including the ones we'd like to use here such as the map method...

It's up to us to add the operators we need. We could add each operator, one-by-one, until we had a custom Observable implementation tuned precisely to our requirements.

E.g., as @Langley's comment above shows:

import 'rxjs/add/operator/map';

Or, if we're lazy we can just pull in the full set of operators:

import 'rxjs/Rx';
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.