配置你的应用

一旦创建了reducer,就可以配置Angular应用程序了。 在您应用的主模块中,简单的将StoreModule.provideStore() 调用添加到@NgModule的导入中:

app/app.module.ts

  1. import {BrowserModule} from '@angular/platform-browser';
  2. import {NgModule} from '@angular/core';
  3. import {FormsModule} from '@angular/forms';
  4. import {HttpModule} from '@angular/http';
  5. import {StoreModule} from '@ngrx/store';
  6. import {EffectsModule} from '@ngrx/effects';
  7. import 'rxjs/Rx';
  8. import {rootReducer} from './store/rootReducer';
  9. import {CounterActions} from './store/actions';
  10. import {CounterEffects} from './store/effects';
  11. import {AppComponent, CounterComponent} from './components';
  12. import {CounterService} from './services';
  13. @NgModule({
  14. imports: [
  15. BrowserModule,
  16. FormsModule,
  17. HttpModule,
  18. StoreModule.provideStore(rootReducer)
  19. ],
  20. declarations: [
  21. AppComponent,
  22. CounterComponent
  23. ],
  24. providers: [
  25. CounterActions,
  26. CounterService
  27. ],
  28. bootstrap: [AppComponent]
  29. })
  30. export class AppModule {
  31. }