NullInjectorError:没有提供RouterStateSerializer的提供者

时间:2019-06-26 12:55:19

标签: angular ngrx-router-store

我已经将一个小小的侧面项目从6号角升级到8号角,现在出现了一个我不理解的错误。

  StaticInjectorError(Platform: core)[StoreRouterConnectingModule -> RouterStateSerializer]: 
    NullInjectorError: No provider for RouterStateSerializer!
    at NullInjector.get (http://localhost:4200/vendor.js:36416:27)
    at resolveToken (http://localhost:4200/vendor.js:36743:24)
    at tryResolveToken (http://localhost:4200/vendor.js:36669:16)
    at StaticInjector.get (http://localhost:4200/vendor.js:36532:20)
    at resolveToken (http://localhost:4200/vendor.js:36743:24)
    at tryResolveToken (http://localhost:4200/vendor.js:36669:16)
    at StaticInjector.get (http://localhost:4200/vendor.js:36532:20)
    at resolveNgModuleDep (http://localhost:4200/vendor.js:58166:29)
    at _createClass (http://localhost:4200/vendor.js:58243:32)
    at _createProviderInstance (http://localhost:4200/vendor.js:58199:26)

有人可以看看吗,给我一些指示。可以在here中找到该代码。预先感谢!

2 个答案:

答案 0 :(得分:1)

我修复了它:)

打开文件cards.module.ts,然后删除导入的StoreRouterConnectingModule 它的冗余。它可以构建并完美运行。

不客气:)

enter image description here

答案 1 :(得分:1)

从6到8,StoreouterConnectingModule的import语句稍有变化,您需要调用ngrx docs here

中给出的forRoot()方法

代码示例:

import { StoreRouterConnectingModule, routerReducer } from '@ngrx/router-store';
import { AppComponent } from './app.component';

@NgModule({
  imports: [
    BrowserModule,
    StoreModule.forRoot({
      router: routerReducer,
    }),
    RouterModule.forRoot([
      // routes
    ]),
    // Connects RouterModule with StoreModule
    StoreRouterConnectingModule.forRoot(),
  ],
  bootstrap: [AppComponent],
})
export class AppModule {}