错误错误:StaticInjectorError角度6

时间:2018-09-21 05:18:45

标签: angular typescript angular5 angular6

从Angular 5迁移到6之后,我面临着Static Injector的问题。错误是:

  

错误错误:StaticInjectorError(AppModule)[StorageService-> LocalStorageService]:     StaticInjectorError(平台:核心)[StorageService-> LocalStorageService]:       NullInjectorError:没有LocalStorageService的提供程序!       在NullInjector.push ../ node_modules/@angular/core/fesm5/core.js.NullInjector.get(core.js:1062)       在resolveToken(core.js:1300)       在tryResolveToken(core.js:1244)       在StaticInjector.push ../ node_modules/@angular/core/fesm5/core.js.StaticInjector.get(core.js:1141)       在resolveToken(core.js:1300)       在tryResolveToken(core.js:1244)       在StaticInjector.push ../ node_modules/@angular/core/fesm5/core.js.StaticInjector.get(core.js:1141)       在resolveNgModuleDep(core.js:8376)       在_createClass(core.js:8423)       在_createProviderInstance(core.js:8393)       在resolveNgModuleDep(core.js:8356)       在_createClass(core.js:8423)       在 createProviderInstance(core.js:8393)       在resolveNgModuleDep(core.js:8356)       在NgModuleRef .push ../ node_modules/@angular/core/fesm5/core.js.NgModuleRef_.get(core.js:9064)       在resolveDep(core.js:9429)       在createClass(core.js:9309)       在createDirectiveInstance(core.js:9186)       在createViewNodes(core.js:10406)       在createRootView(core.js:10320)       在callWithDebugContext(core.js:11351)       在Object.debugCreateRootView [作为createRootView](core.js:10838)       在ComponentFactory_.push ../ node_modules/@angular/core/fesm5/core.js.ComponentFactory_.create(core.js:8666)       在ComponentFactoryBoundToModule.push ../ node_modules/@angular/core/fesm5/core.js.ComponentFactoryBoundToModule.create(core.js:3315)       在ApplicationRef.push ../ node_modules/@angular/core/fesm5/core.js.ApplicationRef.bootstrap(core.js:4550)       在core.js:4358       在Array.forEach()       在PlatformRef.push ../ node_modules/@angular/core/fesm5/core.js.PlatformRef._moduleDoBootstrap(core.js:4358)       在core.js:4324       在ZoneDelegate.push ../ node_modules / zone.js / dist / zone.js.ZoneDelegate.invoke(zone.js:388)       在Object.onInvoke(core.js:3824)       在ZoneDelegate.push ../ node_modules / zone.js / dist / zone.js.ZoneDelegate.invoke(zone.js:387)       在Zone.push ../ node_modules / zone.js / dist / zone.js.Zone.run(zone.js:138)       在zone.js:872       在ZoneDelegate.push ../ node_modules / zone.js / dist / zone.js.ZoneDelegate.invokeTask(zone.js:421)       在Object.onInvokeTask(core.js:3815)       在ZoneDelegate.push ../ node_modules / zone.js / dist / zone.js.ZoneDelegate.invokeTask(zone.js:420)       在Zone.push ../ node_modules / zone.js / dist / zone.js.Zone.runTask(zone.js:188)

import { InfiniteScrollModule } from 'ngx-infinite-scroll';
import { AuthModule } from './auth/auth.module';
import { ConfigurationModule } from './configuration/configuration.module';
import { CoreModule } from './core/core.module';
import { SharedModule } from './shared/shared.module';
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { AppRoutingModule } from './app-routing.module';
import { HomeComponent } from './home/home.component';
import { AppComponent } from './app.component';
import { HttpModule } from '@angular/http'
import { HttpClientModule } from '@angular/common/http';



@NgModule({
  declarations: [
    AppComponent,
    HomeComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    SharedModule,
    CoreModule,
    ConfigurationModule,
    AuthModule,
    InfiniteScrollModule,
    HttpModule,
    HttpClientModule
    

  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

这是我的app.module文件。任何帮助表示赞赏。

1 个答案:

答案 0 :(得分:8)

您需要在模块中的提供程序下添加LocalStorageService。

providers: [LocalStorageService ]