我有一个带有 Init Effect 的效果 =>
@Effect()
init$ = this.actions$.pipe(
ofType(ROOT_EFFECTS_INIT),
map(action =>
new featureActions.GetAllMissionRequest({
projectID: environment.projectId,
projectContextID: environment.projectId
})
)
);
我将其添加到文件底部,我还尝试包含延迟,但当我的商店初始化时,永远不会触发此效果。
我检查了 ngrx 的存储库,但我应用的解决方案没有触发我的功能。
我做错了什么吗?
对于这种情况,您可以在效果上实现 OnInitEffects :
你的Action.ts
export const initEffect = createAction('[ModuleToto] init effect');
yourEffect.ts
@Injectable()
export class YourEffect implements OnInitEffects {
ngrxOnInitEffects(): Action {
return initEffect();
}
init$ = createEffect(
() => this.actions$.pipe(
ofType(initEffect),
map(action =>
new featureActions.GetAllMissionRequest({
projectID: environment.projectId,
projectContextID: environment.projectId
})
)
)
);
}
上看到了这个
为了调度事件,您必须注册您的效果:
@NgModule({
imports: [
EffectsModule.forRoot([MovieEffects])
],
})
export class AppModule {}