错误:商店没有提供商!使用Angular 4.0尝试@ngrx/store时

Ant*_*gov 13 ngrx angular ngrx-store

问题: 错误:商店没有提供商!

我在main.ts中引导商店模块:

platformBrowserDynamic().bootstrapModule(AppModule,[
  provideStore({
    characters, 
    vehicles
  })
]);
Run Code Online (Sandbox Code Playgroud)

并注入vehicle.component.ts:

constructor(
    private _route: ActivatedRoute,
    private _router: Router,
    private _vehicleService: VehicleService,
    private _store: Store<any>
  ) {}
Run Code Online (Sandbox Code Playgroud)

完整的源代码在这里:GitHub,在GitHub Pages上运行的最新版本

PS.将Store添加到提供程序会导致另一个错误:无法解析Store的所有参数:(?,?,?).

Alf*_*Moh 14

我有这个错误,因为,在我的进口组件的自动进口Storeimport { Store } from '@ngrx/store/src/store'代替 import { Store } from '@ngrx/store'; .无论如何,这是在Angular 5中


FRE*_*CIA 7

在app.module.ts中添加:

import { StoreModule } from '@ngrx/store'; // Make sure you import from @ngrx/store

@NgModule({
  imports: [
      StoreModule.forRoot({ characters, vehicles }),
  ...
Run Code Online (Sandbox Code Playgroud)


Man*_*art 5

出于完整性考虑,使用Angular 5 / Ngrx 4.1.1时应为(在app.module.ts中):

import { StoreModule } from '@ngrx/store';
import { reducers } from './reducers/reducers';

@NgModule({
    imports: [     
        StoreModule.forRoot(reducers),
        ...
    ],
    ...
Run Code Online (Sandbox Code Playgroud)

有一个完整的例子在这里