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

相关内容

热门资讯

透视练习!wepoker黑侠辅... 透视练习!wepoker黑侠辅助器(WePoKer开辅助)好像真的是有辅助教程(哔哩哔哩)1、透视练...
透视法门!pokemmo修改器... 透视法门!pokemmo修改器手机版(德普之星官网)原来真的是有辅助神器(哔哩哔哩)1、首先打开po...
透视指南!hhpoker透视脚... 透视指南!hhpoker透视脚本视频(HHpoker必备)总是有辅助软件(哔哩哔哩)在进入hhpok...
透视操作!wepoker辅助器... 透视操作!wepoker辅助器软件下载(AApoker辅助)确实真的有辅助神器(哔哩哔哩)1、wep...
透视大纲!有哪些免费的wpk作... 透视大纲!有哪些免费的wpk作必弊码(HHpoker必备)确实是有辅助神器(哔哩哔哩)1、用户打开应...
透视窍要!epoker透视底牌... 透视窍要!epoker透视底牌(HHpoker安装包)其实真的是有辅助插件(哔哩哔哩)1、epoke...
透视妙计!wepoker透视脚... 透视妙计!wepoker透视脚本是什么(HHpoker德州)本来真的是有辅助app(哔哩哔哩)1、点...
透视妙计!we poker辅助... 透视妙计!we poker辅助器下载(WePoKer数据)果然真的有辅助脚本(哔哩哔哩)1、打开软件...
透视窍门!wpk俱乐部辅助器(... 透视窍门!wpk俱乐部辅助器(HHpoker教程)真是是真的有辅助app(哔哩哔哩)小薇(辅助器软件...
透视手段!佛手大菠萝辅助(AA... 透视手段!佛手大菠萝辅助(AApoker靠谱)都是真的有辅助脚本(哔哩哔哩)小薇(辅助器软件下载)致...