1

I have two actions, action1 which brings control-related things from service all and action2 which bring data related to those control. I want to dispatch action1 and when it successfully completes then only want to dispatch action2.

ngOnInit() {
    this.store.dispatch(new Action1(data1));

    this.store.select(action1Sel).subscribe(res =>{
        this.store.dispatch(new Action2(data2));
     });
       
}

I have like this but looking for a better way of doing it. what is the efficient way to achieve this in ngrx?

LilRazi
  • 690
  • 12
  • 33
  • Hi interesting, I think you have a good approach – IronMan Sep 16 '20 at 00:20
  • you can use action$ from effect library but either of the two is poor practice – Rafi Henig Sep 16 '20 at 01:11
  • Action1 calls a service via an effect, say Effect1. When Effect1 succeeds it should return/dispatch Action2. You only call Action1 directly from your ngOnInit. – wlf Sep 16 '20 at 13:59
  • you should dispatch 2 actions in effects - please check https://stackoverflow.com/questions/41701138/dispatch-multiple-actions-in-one-effect – Denis Varaksin Nov 02 '22 at 15:31

0 Answers0