如何为 ngrx/data 提供初始状态?

问题描述

我在 Angular 11 应用中使用 @ngrx/data,我想为我的 Settings 实体提供初始状态,就像您可以使用 @ngrx/store with StoreModule.forRoot({},{initialState: someInitialState} 一样。>

@ngrx/data 实体提供初始状态的正确方法是什么?

谢谢!

解决方法

使用效果或相关模块的构造函数

export class DataModule {
  constructor(hero: HeroCollection,villain: VillainCollection,fight: FightCollection,store: Store) {
    hero.addManyToCache([]);
    villain.addManyToCache([]);
    fight.addManyToCache([]);
    // .....
  }
}
@Injectable()
export class EntityEffects {
  @Effect()
  public readonly data$ = this.actions$.pipe(
    ofType(ROOT_EFFECTS_INIT),// ....
  );
}