NgRx Store select after subscribe not completing

998 Views Asked by At

I am trying to get data from ngrx store , but as soon as the subscription completes it must go to finalize , and that is not happening

    const { selectIds, selectEntities, selectAll, selectTotal } = adapter.getSelectors(state);
    this.subscription = this.store.select(selectAll)
    .pipe(
          finalize(() => {
            console.log('completed')
          }),
      .subscribe(
        o => {
          //perform some action
        },
        error => {
          console.error(error);
        }
      );

1

There are 1 best solutions below

0
Fateh Mohamed On

If you want to listen to some actions in the store you can try this, imagine you want to listen to CREATE_SUCCESS action and then do some control when your entity is created

import { Actions, ofType } from '@ngrx/effects';
import * as entityActions from './actions'; 


constructor(private actions$: Actions) {
  this.actions.pipe(
    ofType(entityActions.EntityActionTypes.CREATE_SUCCESS)
   ).subscribe(() => { 
     // code executed every time there is a success creation action dispatched 
  })
}