Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 如何实现其他状态的状态数组_Angular_Typescript_Redux_Ngxs - Fatal编程技术网

Angular 如何实现其他状态的状态数组

Angular 如何实现其他状态的状态数组,angular,typescript,redux,ngxs,Angular,Typescript,Redux,Ngxs,我想要一份学习清单。假设这些研究有一个id和一个名称(这样就更简单了) 我目前有一个名为StudyListState的状态,它有一个StudyStateModel数组,它是一个接口 export interface StudyStateModel { id: number; name: string; } export interface StudyListStateModel { studies: StudyStateModel[]; } @State<StudyListS

我想要一份学习清单。假设这些研究有一个id和一个名称(这样就更简单了)

我目前有一个名为StudyListState的状态,它有一个StudyStateModel数组,它是一个接口

export interface StudyStateModel {
 id: number;
 name: string;
}


export interface StudyListStateModel {
  studies: StudyStateModel[];
}

@State<StudyListStateModel>({
  name: 'StudyList',
  defaults: {
    studies: []
  }
})
@Injectable()
export class StudyListState {
 constructor() {}

 @Selector()
 static getStudies(state: StudyListStateModel) {
   return state.studies;
 }

 @Action(AddStudy)
 add(ctx: StateContext<StudyListStateModel>, { payload }: AddStudy) {
   ctx.setState(this.addStudy(payload))
 }

 @Action(PurgeStudies)
 purge(ctx: StateContext<StudyListStateModel>) {
   ctx.setState({ studies: [] });
 }

 private addStudy(payload: StudyStateModel){
   return produce((draft) => {
     draft.studies.push(payload);
   });
 }

}
导出接口StudyStateModel{
id:编号;
名称:字符串;
}
导出接口StudyListStateModel{
研究:StudyStateModel[];
}
@陈述({
名称:'StudyList',
默认值:{
研究:[]
}
})
@可注射()
导出类StudyListState{
构造函数(){}
@选择器()
静态getStudies(状态:StudyListStateModel){
返回状态研究;
}
@行动(研究)
添加(ctx:StateContext,{payload}:AddStudy){
ctx.setState(此.addStudy(有效载荷))
}
@行动(PurgeStudies)
清除(ctx:StateContext){
ctx.setState({studies:[]});
}
私人addStudy(有效负载:StudyStateModel){
退货产品((草稿)=>{
草稿。研究。推送(有效载荷);
});
}
}
但我觉得StudyListState应该由状态组成,而不仅仅是简单对象。因为,如果我想更新一项研究的名称,我想对具体的研究采取一些行动来编辑它,但我不确定你是不是这样做的

提前谢谢,我希望我就在这里