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操作时被正确调用。

相关内容

热门资讯

透视私人局!fishpoker... 透视私人局!fishpoker透视,聚星ai辅助工具下载(透视)解谜教程(有挂方式)-哔哩哔哩1、下...
透视软件!aapoker脚本,... 透视软件!aapoker脚本,wepoker如何设置透视(透视)总结教程(有挂详情)-哔哩哔哩1、下...
据了解!wpk辅助是真的吗,拱... 据了解!wpk辅助是真的吗,拱趴大菠萝辅助神器(透视)曝光教程(详细教程)-哔哩哔哩1、首先打开拱趴...
透视肯定!wepoker辅助器... 透视肯定!wepoker辅助器,aapoker怎么选牌(透视)解迷教程(真的有挂)-哔哩哔哩1、aa...
透视教程!hhpoker有透视... 透视教程!hhpoker有透视功能吗,德普之星透视辅助插件(透视)了解教程(有挂头条)-哔哩哔哩1、...
透视科技!wepokerplu... 透视科技!wepokerplus脚本,hhpoker有没有辅助(透视)开挂教程(讲解有挂)-哔哩哔哩...
记者获悉!约局吧能不能开挂,a... 您好,约局吧能不能开挂这款游戏可以开挂的,确实是有挂的,需要了解加去威信【136704302】很多玩...
围绕透视问题!wepoker透... 围绕透视问题!wepoker透视脚本免费下载,智星德州有脚本吗(透视)透视教程(有挂方针)-哔哩哔哩...
透视辅助!wpk辅助购买,we... 您好,wepoker提高好牌率这款游戏可以开挂的,确实是有挂的,需要了解加去威信【485275054...
目前来看!德普之星透视辅助插件... 目前来看!德普之星透视辅助插件,wepoker线上大神(透视)专业教程(有挂工具)-哔哩哔哩1、德普...