错误:商店没有提供商!使用Angular 4.0

时间:2017-05-30 16:14:17

标签: angular ngrx ngrx-store

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

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

platformBrowserDynamic().bootstrapModule(AppModule,[
  provideStore({
    characters, 
    vehicles
  })
]);

并注入vehicle.component.ts:

constructor(
    private _route: ActivatedRoute,
    private _router: Router,
    private _vehicleService: VehicleService,
    private _store: Store<any>
  ) {}

完整的源代码在这里:GitHub, 最后一个版本正在运行on GitHub Pages

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

3 个答案:

答案 0 :(得分:14)

我遇到此错误,因为在我的组件中自动导入导入的Store import { Store } from '@ngrx/store/src/store'代替 import { Store } from '@ngrx/store'; 。无论如何,这是在Angular 5

答案 1 :(得分:7)

在app.module.ts中添加:

import { Store, StoreModule } from '@ngrx/store';

@NgModule({
  imports:      [
                  StoreModule.provideStore({ characters, vehicles }),
                  ...

答案 2 :(得分:3)

为了完整起见,使用Angular 5 / Ngrx 4.1.1(在app.module.ts中):

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

@NgModule({
    imports: [     
        StoreModule.forRoot(reducers),
        ...
    ],
    ...

有一个完整的示例here

相关问题