HTTP

In order to start making HTTP calls from our Angular app we need to import the angular/http module and register for HTTP services. It supports both XHR and JSONP requests exposed through the HttpModule and JsonpModule respectively. In this section we will be focusing only on the HttpModule.

Setting up angular/http

In order to use the various HTTP services we need to include HttpModule in the imports for the root NgModule. This will allow us to access HTTP services from anywhere in the application.

  1. ...
  2. import { AppComponent } from './app.component'
  3. import { HttpModule } from '@angular/http';
  4. @NgModule({
  5. imports: [
  6. BrowserModule,
  7. ReactiveFormsModule,
  8. FormsModule,
  9. HttpModule
  10. ],
  11. providers: [SearchService],
  12. declarations: [AppComponent],
  13. bootstrap: [AppComponent]
  14. })
  15. export class AppModule {}

原文: https://angular-2-training-book.rangle.io/handout/http/