0

我正在尝试从ngrx store 获取数据,但是一旦订阅完成,它就必须完成,而这并没有发生

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

4

1 回答 1

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 
  })
}
于 2020-02-06T12:05:29.987 回答