首页 > 解决方案 > @angular-redux 实现

问题描述

我正在我的测试应用程序中实现 redux 来管理应用程序状态,我当前的情况是我需要访问后端服务并在服务成功后将响应更新回我的应用程序状态。从那时起,我实现了将处理命中后端服务并更新与 reducer 分离的应用程序状态的效果。但是在调度操作后没有调用效果请检查所做的配置,如果我遗漏了什么,请建议我。

包.json

"@angular-redux/form": "^9.0.1",
"@angular-redux/router": "^9.0.0",
"@angular-redux/store": "^9.0.0",

"@ngrx/core": "^1.2.0",
"@ngrx/effects": "^6.1.0",
"@ngrx/store": "^6.1.0",

在 app.module.ts 里面

EffectsModule.forRoot([TestEffects])

内部组件(调度)

ngOnInit() {
  this.store.dispatch({ type: 'GET_FEEDS' })
}

内部影响 Test.Effects

  @Effect()
   loadFeeds$: Observable<any> = this.actions$.pipe(
       ofType('GET_FEEDS'),
       switchMap((action) =>
           this.feedService.getFeed().pipe(
              map(feeds => console.log("Data received ..." + feeds)),
              catchError(error => of(console.log("Error ..." + error))),
          )
       )
   )

标签: angular-redux

解决方案


推荐阅读