Angular EXCEPTION: No provider for Http
Solution 1:
Import the HttpModule
import { HttpModule } from '@angular/http';
@NgModule({
imports: [ BrowserModule, HttpModule ],
providers: [],
declarations: [ AppComponent ],
bootstrap: [ AppComponent ]
})
export default class AppModule { }
platformBrowserDynamic().bootstrapModule(AppModule);
Ideally, you split up this code in two separate files. For further information read:
- https://v2.angular.io/docs/ts/latest/cookbook/rc4-to-rc5.html
- https://v2.angular.io/docs/ts/latest/guide/ngmodule.html
Solution 2:
>= Angular 4.3
for the introduced HttpClientModule
import { HttpClientModule } from '@angular/common/http';
@NgModule({
imports: [
BrowserModule,
FormsModule, // if used
HttpClientModule,
JsonpModule // if used
],
declarations: [ AppComponent ],
bootstrap: [ AppComponent ]
})
export class AppModule { }
Angular2 >= RC.5
Import HttpModule
to the module where you use it (here for example the AppModule
:
import { HttpModule } from '@angular/http';
@NgModule({
imports: [
BrowserModule,
FormsModule, // if used
HttpModule,
JsonpModule // if used
],
declarations: [ AppComponent ],
bootstrap: [ AppComponent ]
})
export class AppModule { }
Importing the HttpModule
is quite similar to adding HTTP_PROVIDERS
in previous version.