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

时间:2021-02-05 07:50:32

标签: angular ngrx angular-ngrx-data

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

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

谢谢!

1 个答案:

答案 0 :(得分:0)

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

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),
    // ....
  );
}
相关问题