我有一个带有 Init Effect 的效果 =>
@Effect()
init$ = this.actions$.pipe(
ofType(ROOT_EFFECTS_INIT),
map(action =>
new featureActions.GetAllMissionRequest({
projectID: environment.projectId,
projectContextID: environment.projectId
})
)
);
Run Code Online (Sandbox Code Playgroud)
我在文件底部添加了这个,我还尝试包含一个延迟,但是当我的商店初始化时,这个效果永远不会触发。
我检查了 ngrx 的存储库,但我应用的解决方案没有触发我的功能。
难道我做错了什么 ?
小智 5
对于这种情况,您可以在效果上实现 OnInitEffects :
你的Action.ts
export const initEffect = createAction('[ModuleToto] init effect');
Run Code Online (Sandbox Code Playgroud)
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
})
)
)
);
}
Run Code Online (Sandbox Code Playgroud)
我在https://ngrx.io/guide/effects/lifecycle#oniniteffects上看到了这个
| 归档时间: |
|
| 查看次数: |
2083 次 |
| 最近记录: |