订阅后未完成的NgRx商店选择

时间:2020-02-06 11:31:50

标签: angular ngrx ngrx-store ngrx-effects ngrx-store-4.0

我正在尝试从ngrx存储中获取数据,但是一旦订阅完成,它就必须完成,这不会发生

    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 个答案:

答案 0 :(得分:0)

如果您想听商店中的某些操作,可以尝试一下,想象一下您想听CREATE_SUCCESS操作,然后在创建实体时进行一些控制

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 
  })
}