The documentation for http has this example:
import {Http, HTTP_PROVIDERS} from 'angular2/http';
@Component({
selector: 'http-app',
viewProviders: [HTTP_PROVIDERS],
templateUrl: 'people.html'
})
class PeopleComponent {
constructor(http: Http) {
http.get('people.son')]
.map(res => res.json())
.subscribe(people => this.people = people);
}
}
However, I need to add this line: import 'rxjs/add/operator/map to make it work.
Do I have my configuration different or the import is missing in the example?
The Server Communication dev guide 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
Observablein therxjs/Observablemodule, a version that lacks almost all operators including the ones we'd like to use here such as themapmethod...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 you stated, add map explicitly:
import 'rxjs/add/operator/map';
Or, if we're lazy we can just pull in the full set of operators:
import 'rxjs/Rx';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With