首页 > 解决方案 > 为什么我收到此错误:StaticInjectorError(AppModule)[VideosService -> Http

问题描述

我收到此错误:

core.js:1449 ERROR Error: Uncaught (in promise): Error: StaticInjectorError(AppModule)[VideosService -> Ht**strong text**tp]: 
  StaticInjectorError(Platform: core)[VideosService -> Http]: 
    NullInjectorError: No provider for Http!
Error: StaticInjectorError(AppModule)[VideosService -> Http]: 
  StaticInjectorError(Platform: core)[VideosService -> Http]: 
    NullInjectorError: No provider for Http!

标签: angular

解决方案


您可能必须导入HttpModuleapp.module.ts

// main.ts
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { BrowserModule } from '@angular/platform-browser';
import { HttpModule } from '@angular/http';
import { AppComponent } from './app.component';

@NgModule({
  imports: [ BrowserModule, HttpModule ],
  declarations: [ AppComponent ],
  bootstrap: [ AppComponent ]
})
class AppModule { }

platformBrowserDynamic().bootstrapModule(AppModule);

推荐阅读