AngularNgrx-在dispatch操作时,Effects没有被调用。
创始人
2024-10-28 17:01:19
0

这可能是由于在dispatch前未注入Effect源或在提供程序中未正确声明导致的。以下是一个示例:

在您的模块中引入Effects和Store模块:

import { EffectsModule } from '@ngrx/effects'; import { StoreModule } from '@ngrx/store';

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

在您的组件或服务文件中,创建一个action并使用dispatch将其发送到store:

import { MyAction } from '../store/my-action.actions'; import { Store } from '@ngrx/store';

constructor(private store: Store) {}

triggerAction() { this.store.dispatch(new MyAction()); }

在您的Effect中,监听您的Action并执行所需的操作:

import { Injectable } from '@angular/core'; import { Actions, Effect, ofType } from '@ngrx/effects'; import { MyAction } from '../store/my-action.actions'; import { tap } from 'rxjs/operators';

@Injectable() export class MyEffect { @Effect({dispatch: false}) myAction$ = this.actions$.pipe( ofType(MyAction), tap(() => console.log('MyAction was dispatched!')) );

constructor(private actions$: Actions) {}

}

确认在提供程序中正确声明effect:

import { EffectsModule } from '@ngrx/effects'; import { MyEffect } from './my-effect.effects';

@NgModule({ imports: [ ... EffectsModule.forFeature([MyEffect]), ... ], declarations: [...], providers: [ MyEffect, ... ] })

这些步骤应该能够使Effects在dispatch操作时被正确调用。

相关内容

热门资讯

九分钟教程!微乐小程序黑科技,... 九分钟教程!微乐小程序黑科技,微乐自建房插件详细教程(开挂)其实有挂(2026)1、微乐小程序黑科技...
2026版教学!微乐小程序黑科... 2026版教学!微乐小程序黑科技,小程序微乐辅助器免费版(透视)好像真的有挂(哔哩哔哩)小程序微乐辅...
六分钟教程!微乐小程序黑科技,... 六分钟教程!微乐小程序黑科技,微乐自建房怎么提高运气(开挂)都是真的是有挂(2026)1、首先打开微...
透视系统!微乐小程序黑科技,陕... 透视系统!微乐小程序黑科技,陕西微乐小程序修改器(透视)原来有挂(哔哩哔哩)1、不需要AI权限,帮助...
第4分钟下载!微乐小程序黑科技... 第4分钟下载!微乐小程序黑科技,微乐自建房辅助软件下载(开挂)好像真的是有挂(2026)1、许多玩家...
在玩家背景下!微乐小程序黑科技... 在玩家背景下!微乐小程序黑科技,微乐小程序辅助器出租(透视)都是是真的挂(哔哩哔哩)暗藏猫腻,小编详...
一分钟开挂!微乐小程序黑科技,... 一分钟开挂!微乐小程序黑科技,微乐科技软件下载(开挂)竟然是有挂(2026)1、微乐小程序黑科技免费...
推出新举措!微乐小程序免费黑科... 推出新举措!微乐小程序免费黑科技,微信小程序怎么开挂(透视)竟然真的是有挂(哔哩哔哩)1、每一步都需...
4分钟透视!微乐小程序免费黑科... 4分钟透视!微乐小程序免费黑科技,微乐小程序怎么挂脚本(开挂)好像是真的挂(2026)1)微乐小程序...
透视中牌率!微乐小程序黑科技,... 透视中牌率!微乐小程序黑科技,微乐自建房辅助工具官网(透视)好像是有挂(哔哩哔哩);1、金币登录送、...